conditional includes
joe at modcomp.UUCP
joe at modcomp.UUCP
Sat Jan 21 05:53:00 AEST 1989
Hi, fellow netlanders,
Several of you responded to my query about what C compilers, if any, provide
their users with a convenient conditional include facility. As promised,
I'm summarizing (read: liberally plagiarizing) your letters in this response.
1. The Objective-C language (used on the NeXT) has exactly the feature
described. The keyword used is "#import".
2. The "High C" compiler for the IBM PC/RT supports once-only includes. It
prevents multiple includes based on filename, so referencing a file by
different names will result in multiple inclusion.
3. One compiler (unnamed) has a cpp pragma "#pragma idempotent" that is
inserted into the header file. Any subsequent include of that filename
is skipped.
4. A combination of (3) and the original solution results in an effective
solution which does not require any language extensions: replace
"#pragma idempotent" with the lines:
#ifdef <whatever>
#define <whatever>
and add a "#endif" to the end of the include file. Controlling multiple
inclusion from within the file itself solves the problem mentioned in (2)
as well as the excessive wordiness of the original solution.
I have assumed that all respondents prefer to remain anonymous. My
apologies if that assumption is wrong.
joe korty
uunet!modcomp!joe
More information about the Comp.lang.c
mailing list