145 lines
7.2 KiB
HTML
145 lines
7.2 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- Copyright (C) 1987-2016 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation. A copy of
|
|
the license is included in the
|
|
section entitled "GNU Free Documentation License".
|
|
|
|
This manual contains no Invariant Sections. The Front-Cover Texts are
|
|
(a) (see below), and the Back-Cover Texts are (b) (see below).
|
|
|
|
(a) The FSF's Front-Cover Text is:
|
|
|
|
A GNU Manual
|
|
|
|
(b) The FSF's Back-Cover Text is:
|
|
|
|
You have freedom to copy and modify this GNU Manual, like GNU
|
|
software. Copies published by the Free Software Foundation raise
|
|
funds for GNU development. -->
|
|
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>The C Preprocessor: Header Files</title>
|
|
|
|
<meta name="description" content="The C Preprocessor: Header Files">
|
|
<meta name="keywords" content="The C Preprocessor: Header Files">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="index.html#Top" rel="up" title="Top">
|
|
<link href="Include-Syntax.html#Include-Syntax" rel="next" title="Include Syntax">
|
|
<link href="The-preprocessing-language.html#The-preprocessing-language" rel="prev" title="The preprocessing language">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.indentedblock {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style:oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nocodebreak {white-space:nowrap}
|
|
span.nolinebreak {white-space:nowrap}
|
|
span.roman {font-family:serif; font-weight:normal}
|
|
span.sansserif {font-family:sans-serif; font-weight:normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
|
|
<a name="Header-Files"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Macros.html#Macros" accesskey="n" rel="next">Macros</a>, Previous: <a href="Overview.html#Overview" accesskey="p" rel="prev">Overview</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<a name="Header-Files-1"></a>
|
|
<h2 class="chapter">2 Header Files</h2>
|
|
|
|
<a name="index-header-file"></a>
|
|
<p>A header file is a file containing C declarations and macro definitions
|
|
(see <a href="Macros.html#Macros">Macros</a>) to be shared between several source files. You request
|
|
the use of a header file in your program by <em>including</em> it, with the
|
|
C preprocessing directive ‘<samp>#include</samp>’.
|
|
</p>
|
|
<p>Header files serve two purposes.
|
|
</p>
|
|
<ul>
|
|
<li> <a name="index-system-header-files"></a>
|
|
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.
|
|
|
|
</li><li> 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.
|
|
</li></ul>
|
|
|
|
<p>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
|
|
declarations 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.
|
|
</p>
|
|
<p>In C, the usual convention is to give header files names that end with
|
|
<samp>.h</samp>. It is most portable to use only letters, digits, dashes, and
|
|
underscores in header file names, and at most one dot.
|
|
</p>
|
|
<table class="menu" border="0" cellspacing="0">
|
|
<tr><td align="left" valign="top">• <a href="Include-Syntax.html#Include-Syntax" accesskey="1">Include Syntax</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Include-Operation.html#Include-Operation" accesskey="2">Include Operation</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Search-Path.html#Search-Path" accesskey="3">Search Path</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Once_002dOnly-Headers.html#Once_002dOnly-Headers" accesskey="4">Once-Only Headers</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Alternatives-to-Wrapper-_0023ifndef.html#Alternatives-to-Wrapper-_0023ifndef" accesskey="5">Alternatives to Wrapper #ifndef</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Computed-Includes.html#Computed-Includes" accesskey="6">Computed Includes</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="Wrapper-Headers.html#Wrapper-Headers" accesskey="7">Wrapper Headers</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
<tr><td align="left" valign="top">• <a href="System-Headers.html#System-Headers" accesskey="8">System Headers</a>:</td><td> </td><td align="left" valign="top">
|
|
</td></tr>
|
|
</table>
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Macros.html#Macros" accesskey="n" rel="next">Macros</a>, Previous: <a href="Overview.html#Overview" accesskey="p" rel="prev">Overview</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|