ugh.book

(singke) #1
Programming in Plato’s Cave 181

Dennis never found the problem with his Makefile. He’s now stuck in a
dead-end job where he has to wear a paper hat and maintains the sendmail
configuration files for a large state university in the midwest. It’s a damn
shame.


Header Files


C has these things called header files. They are files of definitions that are
included in source files at compilation time. Like most things in Unix, they
work reasonably well when there are one or two of them but quickly
become unwieldy when you try to do anything serious.


It is frequently difficult to calculate which header files to include in your
source file. Header files are included by using the C preprocessor #include
directive. This directive has two syntaxes:


#include <header1.h>

and:


#include "header2.h"

The difference between these two syntaxes is implementation dependent.
This basically means that the implementation is free to do whatever the hell
it wants.


Let’s say Dennis has a friend named Joey who is also a novice Unix pro-
grammer. Joey has a C program named foo.c that has some data structure
definitions in foo.h, which lives in the same directory. Now, you probably
know that “foo” is a popular name among computer programmers. It turns
out that the systems programmer for Joey’s machine also made a file
named foo.h and stored it in the default include file directory, /usr/include.


Poor Joey goes to compile his foo.c program and is surprised to see multi-
ple syntax errors. He is puzzled since the compiler generates a syntax error
every time he mentions any of the data structures defined in foo.h. But the
definitions in foo.h look okay.


You and I probably know that the Joey probably has:


#include <foo.h>

in his C file instead of:


#include "foo.h"
Free download pdf