#include "filename.h" does not mean "include user file"

Ned Nowotny ned at pebbles.cad.mcc.com
Fri Mar 23 02:20:36 AEST 1990


In article <1990Mar16.003404.29369 at aqdata.uucp> sullivan at aqdata.uucp (Michael T. Sullivan) writes:
=>:From article <6928 at cadillac.CAD.MCC.COM>, by ned at pebbles.cad.mcc.com (Ned Nowotny):
=>> 
=>> As a result of problems similar to the one described above, it seems that
=>> programmers should always use the #include <filename> form unless they
=>> have a specific, well defined situation in which the behavior of the
=>> #include "filename" form is clearly desired.  The #include "filename" form
=>
=>I have never thought of "filename" as meaning "an include file in the
=>current directory".  My usage has been to use <file> when the file is
=>a Unix supplied header file and to use "file" otherwise.  This gives
=>future programmers a clue as to where to look for the header file.  Now,
=>you may have package supplied header files in /usr/include on your system--
=>that's fine and "file" will still find it but not all systems will have
=>package-defined header files in /usr/include.  Also, if a future programmer
=>is porting some code and cpp can't find <file>, then the programmer knows
=>that the system is lacking a certain header file and that he/she better
=>get his/her hands on one, instead of wondering why the code came incomplete.

However, given that #include "filename" does behave differently from
#include <filename> and that this behavior can produce undesirable results
in some circumstances, you should be using comments to indicate which include
files are system header files, which are package supplied header files and
which are local application header files.  After all, #include "filename"
does not mean "not a system header file" in any sense.

Aside from code produced by code generators like YACC, LEX, BISON, and FLEX
where all files produced are generally written to and kept in a single
directory, is there any compelling reason to ever use #include "filename"?
My opinion is that there is not and that programmers should not be using the
form unless there is a very special circumstance in which the behavior of
#include "filename" is exactly the behavior desired.  The wish to not
specify a particular directory with the -I flag on a compiler command line
is not a sufficiently compelling reason.

Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX  78720  Ph: (512) 338-3715
ARPA: ned at mcc.com                   UUCP: ...!cs.utexas.edu!milano!cadillac!ned
-------------------------------------------------------------------------------
"We have ways to make you scream." - Intel advertisement in the June 1989 DDJ.



More information about the Comp.std.c mailing list