Include Operation; Search Path - Red Hat ENTERPRISE LINUX 3 - USING CPP Using Instructions

Using cpp, the c preprocessor
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING CPP:
Table of Contents

Advertisement

8

2.2. Include Operation

The
directive works by directing the C preprocessor to scan the specified file as input
#include
before continuing with the rest of the current file. The output from the preprocessor contains the
output already generated, followed by the output resulting from the included file, followed by the
output that comes from the text after the
as follows,
header.h
char *test (void);
and a main program called
int x;
#include "header.h"
int
main (void)
{
puts (test ());
}
the compiler will see the same token stream as it would if
int x;
char *test (void);
int
main (void)
{
puts (test ());
}
Included files are not limited to declarations and macro definitions; those are merely the typical uses.
Any fragment of a C program can be included from another file. The include file could even contain
the beginning of a statement that is concluded in the containing file, or the end of a statement that was
started in the including file. However, a comment or a string or character constant may not start in the
included file and finish in the including file. An unterminated comment, string constant or character
constant in an included file is considered to end (with an error message) at the end of the file.
To avoid confusion, it is best if header files contain only complete syntactic units--function declara-
tions or definitions, type declarations, etc.
The line following the
even if the included file lacks a final newline.

2.3. Search Path

GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it
otherwise, it will look for headers requested with
/usr/local/include
/usr/lib/gcc-lib/
/usr/
/include
target
#include
that uses the header file, like this,
program.c
directive is always treated as a separate line by the C preprocessor,
#include
/
/include
target
version
directive. For example, if you have a header file
program.c
©

#include
file
Chapter 2. Header Files
read
in:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Enterprise linux 3

Table of Contents