CompuServe Messages

Size_t existence

    27-Jul-93 07:04:06
Sb: #7605-Size_t existence
Fm: Phil Shapiro 72430,2320
To: Syndesis 76004,1763
"Every other compiler I've seen, that wants to insure that an include file is only included once, uses a simple system of #ifndef / #define / #endif instead of resorting to an entirely non-portable pragma." Saying that one is simpler than the other is a matter of taste. From the ANSI C library writer's perspective portability isn't a concern, so using a non-portable pragma is perfectly acceptable. The really ugly thing about using a macro definition, IMO, is that it tends to breed code like: #ifndef __FOO__ #include "foo.h" #endif etc. This kind of code is messy, and typically is only there to speed up the compile (ie, it has no semantic effect on the source). This is again a matter of taste, but I feel that the increase in source clarity is worth the extra compiler baggage. Using #pragma one relieves you from keeping track of what the file name happens to be, and reduces the work involved in changing a header file's name. "Thanks for the tip on #pragma once == #define _H_stdio if that's what you meant." This is only true in THINK C. "So what happens if you put any code before #pragma once? Does it get examined twice? Or does this pragma magically prevent that include from being examined in any way?" As TFM will tell you, #pragma once marks a file as "read-once". Such files are never re-read or re-opened. -phil