Multiple includes of standard headers
Jim Gardner
jagardner at watmath.waterloo.edu
Fri Jun 24 03:06:39 AEST 1988
In article <8131 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn) writes:
> So, for example, our header "Dx.h" uses the name
>"Dx_HDR_INCLUDED" for its one-time lockout flag. [...]
>
>>This type of thing sure would be handy in the Unix header files (hint, hint).
>
>A start had already been made at doing this, and it is essential for
>ANSI C conformance. (The C implementation will have to use macro
>names starting with underscore for its lockout flags.)
But can you lock out a standard header file? Section 4.1.2 says "...; each
may be included more than once in a given scope, with no effect different from
being included once, except that the effect of including <assert.h> depends
on the definition of NDEBUG."
If the effect of the first inclusion is to define a macro, say, putc(),
then the effect of the second must be no different so it also must define
putc(). E.g.,
#include <stdio.h>
#undef putc
#include <stdio.h>
f() { putc(c,f); }
At f(), putc should be a macro again. I don't really like this behaviour
(I prefer having the locking out technique available), but the wording
and the exception with <assert.h> seem to indicate that you cannot lock
out the standard headers. Even if my interpretation is wrong (I hope it is!),
I think the wording should be changed to make it clear to a non-lawyer.
More information about the Comp.lang.c
mailing list