Liste des Groupes | Revenir à cl c |
On 2025-04-02, bart <bc@freeuk.com> wrote:IMHO, it would be better if headers were explicitly defined as including other headers. The documentation of <string.h> should say that it includes <stddef.h>. That way everything is defined in one and only one header, in a clear manner, without forcing users to manually include extra headers in a specific order.So it is not true that you need include stddef.h, nor obvious that thatIt's documented as the canonical source of NULL.
is where NULL is defined, if you are used to having it available indirectly.
In C90, now 35 years ago, it was written up like this:
7.1.6 Common definitions <stddef.h>
The following types and macros are defined in the standard header
<stddef.h>. Some are also defined in other headers, as noted in their
respective subclauses.
...
The macros are
NULL
which expands to an implementation-defined null pointer constant: and
offsetof(type, member-designator)
... etc
There is no other easy way to find that out. An implementation could directly
stick #define NULL into every header that is either allowed or required to
reveal that macro, and so from that you would not know which headers are
required to provide it.
Many things are not going to be "obvious" if you don't use documentation.
(In my opinion, things would be better if headers were not allowed to behave as
if they include other headers, or provide identifiers also given in other
heards. Not in ISO C, and not in POSIX. Every identifier should be declared in
exactly one home header, and no other header should provide that definition.
Programs ported from one Unix to another sometimes break for no other reason
than this! On the original platform, a header provided a certain identifier
which it is not required to; on the new platform that same header doesn't do
that.)
Les messages affichés proviennent d'usenet.