Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Suggestion: #pragma STDC tryinclude <foo.h>

1 view
Skip to first unread message

Hallvard B Furuseth

unread,
Jun 12, 2009, 9:43:16 AM6/12/09
to
N1348 suggests three ways try conditional inclusion if the program
does not know if a header is available:
#if __STDC_HAS_FOO__ followed by #include <foo.h>,
#if available(<foo.h>) followed by #include <foo.h>,
#if include(<foo.h>).

However, the first will only be predefined for standard C headers.
The last two break in pre-C1X compilers. Maybe they'll also need
different quoting of \ and " than a plain #include statement.

Instead I suggest:
#pragma STDC tryinclude <foo.h>
#if __STDC_TRYINCLUDE__ /* nonzero iff last tryinclude succeeded */

Programs may usually prefer to #ifndef <macro defined in foo.h> instead
of __STDC_TRYINCLUDE__. If nothing else, the FOO_H or whatever which
foo.h will commonly use to ensure its contents is only read once.
However some include files define no useful macro for this purpose,
and those who do might still rename FOO_H in a later version.

--
Hallvard

0 new messages