[comp.lang.c] A solution to the multiple inclusio

joe@modcomp.UUCP (10/25/89)

Lawrence Crowl writes:
> Each include file defines a symbol (preferably related to its name).  For
> example, in foo.h:
>         #define foo_h
> Each file that includes foo.h, protects the inclusion with a #ifndef:
>         #ifndef foo_h
>         #include "foo.h"
>         #endif foo_h
> I have used this solution as a matter of course since shortly after I learned
> to program in C.  It is an obvious solution, and leads me to wonder why it is
> not common practice.  Any explainations?

Well, for one thing, it's clumsy to enter.  For another, it's clumsy to
read.  Finally, it places this dirt at point-of-use, rather than
point-of-definition, where it really belongs (reason: thingys defined
once; used many times).  For many of us, these are sufficient reasons
to put this mechanism entirely in the include file, in spite of the
obvious (machine) inefficiencies involved.
--
joe korty			"for every vengence there is an equal and
uunet!modcomp!joe		opposite revengence." (from Cartoon Laws)

mcdonald@uxe.cso.uiuc.edu (10/30/89)

    
   > >   #include FRED_H
    
>    Please be alert for problems.  K&R requires the token after the
>    "#include" to be a filename enclosed in double quotes or angle
>    brackets, not an arbitrary symbol.

Quoted without permission from "The C Programming Language" by
Kernighan and Ritchie, Prentice Hall, copyright 1988 (page231):

Finally, a directive of the form
   # include token-sequence

not matching one of the previous formsis interpreted by expanding the
token sequence as for normal text; one of the two forms with
<...> or "..." must result, and it is then treated as described
previously"

So, if FRED_H expands to "fred.h" it is perfectly legal. If is stays
as-is, it is illegal.

Another question arises: earlier K&R say "The characters in the filename
must not include >  [if it started with <] or the newline and 
the effect in undefined if it 
contains any of ", ',\, or /*."

Shouldn't that be "implementation defined" rather than undefined -
the most common operating system in the world uses "\" as a file
path separator.

Doug McDonald