A solution to the multiple inclusion problem

Rob Sartin sartin at hplabsz.HPL.HP.COM
Wed Oct 25 05:35:57 AEST 1989


In article <1659 at atanasoff.cs.iastate.edu> hascall at atanasoff.UUCP (John Hascall) writes:
>    Since the impending ANSI standard requires that including a file more
>    than once have exactly the same effect as including it once...why can't
>    a compiler just ignore #includes for files it has already #included???
>    (at least for the "standard" includes)

That introduces some potential oddities for <assert.h> which doesn't try
to prevent from being included twice.  My C++ 2.0 assert.h includes a
comment that says:

/* This header file intentionally has no wrapper, since the user
*  may want to re-include it to turn off/on assertions for only
*  a portion of the source file.
*/

>    but, does anyone do this thing in the *same* file??

=begin foo.c
#define NDEBUG
#include <assert.h>
int tested_function()
{
...
}

#undef NDEBUG
#include <assert.h>
int untested_function()
{
}
=end foo.c

Rob Sartin			internet: sartin at hplabs.hp.com
Software Technology Lab 	uucp    : hplabs!sartin
Hewlett-Packard			voice	: (415) 857-7592



More information about the Comp.lang.c mailing list