A solution to the multiple inclusion problem

John Hascall hascall at atanasoff.cs.iastate.edu
Tue Oct 24 10:24:04 AEST 1989


In some article with a silly huge id#, Lawrence Crowl writes:
}In article <14240 at well.UUCP> nagle at well.UUCP (John Nagle) notes three
}solutions to the multiple file inclusion problem:
 
}(2) Modifying the semantics of #include to only include a file once.  This is
}    incompatible with the current definition of #include.
 
}  [yet another scheme...]

    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)
    
    Any comments from the ANSI mavens?


    I know some people use stuff like:

 main.c:                              subr.c:
    #define MAINDEF 1                    #define MAINDEF 0
    #include "vars.h"                    #include "vars.h"
    main()                               subrtn()
    { ...                                { ...

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

John Hascall



More information about the Comp.lang.c mailing list