Include files

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 28 14:18:11 AEST 1989


In article <10991 at umn-cs.CS.UMN.EDU> raghavan at umn-cs.cs.umn.edu (Vijay Raghavan) writes:
- Is the Sun style of surrounding the text of standard "include" files 
-with a #ifndef-#endif pair really okay? Specifically, does the standard
-condone/permit/require stdio.h (say) to have the following structure: 
-#ifndef FILE 
- ...
-#define FILE struct _iobuf
- ...
-#endif !__FILE

Well, more or less.  There are several detailed points involved here.

- If it does, programs like the following should not compile: 
-main() {
-#include <stdio.h>
-FILE *xx;
-... 
-}
-proc1() {
-#include <stdio.h>
-FILE *yy;
-...
-}

The first point is that the standard headers may be included only
outside all function bodies (i.e. at file scope level).

The next point is that a #defined macro's scope extends to the end
of the translation unit, not just to the end of a block.

The third point is that FILE should be a typedef, not a #define.

The final point is that the standard headers may be included more
than once with no effect different from being included exactly once.
This is what the "#ifndef FILE" was attempting to accomplish.



More information about the Comp.lang.c mailing list