Header-Files.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1987-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation. A copy of
  7. the license is included in the
  8. section entitled "GNU Free Documentation License".
  9. This manual contains no Invariant Sections. The Front-Cover Texts are
  10. (a) (see below), and the Back-Cover Texts are (b) (see below).
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The C Preprocessor: Header Files</title>
  20. <meta name="description" content="The C Preprocessor: Header Files">
  21. <meta name="keywords" content="The C Preprocessor: Header Files">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="index.html#Top" rel="up" title="Top">
  30. <link href="Include-Syntax.html#Include-Syntax" rel="next" title="Include Syntax">
  31. <link href="The-preprocessing-language.html#The-preprocessing-language" rel="prev" title="The preprocessing language">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Header-Files"></a>
  63. <div class="header">
  64. <p>
  65. 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> &nbsp; [<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>
  66. </div>
  67. <hr>
  68. <a name="Header-Files-1"></a>
  69. <h2 class="chapter">2 Header Files</h2>
  70. <a name="index-header-file"></a>
  71. <p>A header file is a file containing C declarations and macro definitions
  72. (see <a href="Macros.html#Macros">Macros</a>) to be shared between several source files. You request
  73. the use of a header file in your program by <em>including</em> it, with the
  74. C preprocessing directive &lsquo;<samp>#include</samp>&rsquo;.
  75. </p>
  76. <p>Header files serve two purposes.
  77. </p>
  78. <ul>
  79. <li> <a name="index-system-header-files"></a>
  80. System header files declare the interfaces to parts of the operating
  81. system. You include them in your program to supply the definitions and
  82. declarations you need to invoke system calls and libraries.
  83. </li><li> Your own header files contain declarations for interfaces between the
  84. source files of your program. Each time you have a group of related
  85. declarations and macro definitions all or most of which are needed in
  86. several different source files, it is a good idea to create a header
  87. file for them.
  88. </li></ul>
  89. <p>Including a header file produces the same results as copying the header
  90. file into each source file that needs it. Such copying would be
  91. time-consuming and error-prone. With a header file, the related
  92. declarations appear in only one place. If they need to be changed, they
  93. can be changed in one place, and programs that include the header file
  94. will automatically use the new version when next recompiled. The header
  95. file eliminates the labor of finding and changing all the copies as well
  96. as the risk that a failure to find one copy will result in
  97. inconsistencies within a program.
  98. </p>
  99. <p>In C, the usual convention is to give header files names that end with
  100. <samp>.h</samp>. It is most portable to use only letters, digits, dashes, and
  101. underscores in header file names, and at most one dot.
  102. </p>
  103. <table class="menu" border="0" cellspacing="0">
  104. <tr><td align="left" valign="top">&bull; <a href="Include-Syntax.html#Include-Syntax" accesskey="1">Include Syntax</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  105. </td></tr>
  106. <tr><td align="left" valign="top">&bull; <a href="Include-Operation.html#Include-Operation" accesskey="2">Include Operation</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  107. </td></tr>
  108. <tr><td align="left" valign="top">&bull; <a href="Search-Path.html#Search-Path" accesskey="3">Search Path</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  109. </td></tr>
  110. <tr><td align="left" valign="top">&bull; <a href="Once_002dOnly-Headers.html#Once_002dOnly-Headers" accesskey="4">Once-Only Headers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  111. </td></tr>
  112. <tr><td align="left" valign="top">&bull; <a href="Alternatives-to-Wrapper-_0023ifndef.html#Alternatives-to-Wrapper-_0023ifndef" accesskey="5">Alternatives to Wrapper #ifndef</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  113. </td></tr>
  114. <tr><td align="left" valign="top">&bull; <a href="Computed-Includes.html#Computed-Includes" accesskey="6">Computed Includes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  115. </td></tr>
  116. <tr><td align="left" valign="top">&bull; <a href="Wrapper-Headers.html#Wrapper-Headers" accesskey="7">Wrapper Headers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  117. </td></tr>
  118. <tr><td align="left" valign="top">&bull; <a href="System-Headers.html#System-Headers" accesskey="8">System Headers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  119. </td></tr>
  120. </table>
  121. <hr>
  122. <div class="header">
  123. <p>
  124. 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> &nbsp; [<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>
  125. </div>
  126. </body>
  127. </html>