Header Files; Include Syntax - 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

A header file is a file containing C declarations and macro definitions (Refer to Chapter 3 Macros)
to be shared between several source files. You request the use of a header file in your program by
including it, with the C preprocessing directive
Header files serve two purposes.
System header files declare the interfaces to parts of the operating system. You include them in your
program to supply the definitions and declarations you need to invoke system calls and libraries.
Your own header files contain declarations for interfaces between the source files of your program.
Each time you have a group of related declarations and macro definitions all or most of which are
needed in several different source files, it is a good idea to create a header file for them.
Including a header file produces the same results as copying the header file into each source file that
needs it. Such copying would be time-consuming and error-prone. With a header file, the related dec-
larations appear in only one place. If they need to be changed, they can be changed in one place, and
programs that include the header file will automatically use the new version when next recompiled.
The header file eliminates the labor of finding and changing all the copies as well as the risk that a
failure to find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with
only letters, digits, dashes, and underscores in header file names, and at most one dot.

2.1. Include Syntax

Both user and system header files are included using the preprocessing directive
two variants:
§
¨
#include
file
This variant is used for system header files. It searches for a file named
system directories. You can prepend directories to this list with the
12 Invocation).
#include "
"
file
This variant is used for header files of your own program. It searches for a file named
in the directory containing the current file, then in the same directories used for
The argument of
#include
a string constant in that comments are not recognized, and macro names are not expanded. Thus,
§
#include
x/*y
However, if backslashes occur within
characters. None of the character escape sequences appropriate to string constants in C are processed.
Thus,
#include "x\n\\y"
pret
as a pathname separator. All of these also interpret
\
only
.)
/
It is an error if there is anything (other than comments) on the line after the file name.
, whether delimited with quote marks or angle brackets, behaves like
¨
specifies inclusion of a system header file named
file
specifies a filename containing three backslashes. (Some systems inter-
.
#include
, they are considered ordinary text characters, not escape
the same way. It is most portable to use
/
Chapter 2.

Header Files

. It is most portable to use
.h
#include
in a standard list of
file
option (Refer to Chapter
-I
file
§
file
.
x/*y
. It has
first
¨
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Enterprise linux 3

Table of Contents