Subject: Re: problems with arpa/inet.h
To: None <current-users@NetBSD.ORG>
From: Olaf Seibert <rhialto@polder.ubc.kun.nl>
List: current-users
Date: 06/09/1998 12:31:00
In <Pine.NEB.3.95.980609110228.206W-100000@apb.iafrica.com> Alan Barrett <apb@iafrica.com> writes:

>Mike Long <mikel@shore.net> said:
>> Multiple inclusion protection does not keep cpp from reading the whole
>> header each time it is #included. 
>
>This is just a SMOP.  Nothing prevents the compiler from noticing when a
>file consists entirely of comments, blank lines, and lines that are
>wrapped in a single #if or #ifdef block, keeping a record of the relevant
>#if or #ifdef conditions, testing those conditions when you try to
>#include the same file again, and deciding not to bother opening the file
>at all if the conditions are such that including the file would not be
>useful. 
>
>--apb (Alan Barrett)

And in fact, cccp (gnu's cpp) already does this. From the cpp.info file,
node Once-Only:

   The standard way to do this is to enclose the entire real contents
of the file in a conditional, like this:

     #ifndef FILE_FOO_SEEN
     #define FILE_FOO_SEEN
     
     THE ENTIRE FILE
     
     #endif /* FILE_FOO_SEEN */

[...]
   The GNU C preprocessor is programmed to notice when a header file
uses this particular construct and handle it efficiently.  If a header
file is contained entirely in a `#ifndef' conditional, then it records
that fact.  If a subsequent `#include' specifies the same file, and the
macro in the `#ifndef' is already defined, then the file is entirely
skipped, without even reading it.

-Olaf.
--
___ Olaf 'Rhialto' Seibert                D787B44DFC896063 4CBB95A5BD1DAA96 
\X/ * You are not expected to understand this.    rhialto@polder.ubc.kun.nl