📄 obsolete-once-only-headers.html
字号:
<html lang="en">
<head>
<title>The C Preprocessor</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The C Preprocessor">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
<!--
Copyright © 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
<p>Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 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".
<p>This manual contains no Invariant Sections. The Front-Cover Texts are
(a) (see below), and the Back-Cover Texts are (b) (see below).
<p>(a) The FSF's Front-Cover Text is:
<p>A GNU Manual
<p>(b) The FSF's Back-Cover Text is:
<p>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.
-->
</head>
<body>
<div class="node">
<p>
Node:<a name="Obsolete%20once-only%20headers">Obsolete once-only headers</a>,
Previous:<a rel="previous" accesskey="p" href="Assertions.html#Assertions">Assertions</a>,
Up:<a rel="up" accesskey="u" href="Obsolete-Features.html#Obsolete%20Features">Obsolete Features</a>
<hr><br>
</div>
<h4 class="subsection">Obsolete once-only headers</h4>
<p>CPP supports two more ways of indicating that a header file should be
read only once. Neither one is as portable as a wrapper <code>#ifndef</code>,
and we recommend you do not use them in new programs.
<p>In the Objective-C language, there is a variant of <code>#include</code>
called <code>#import</code> which includes a file, but does so at most once.
If you use <code>#import</code> instead of <code>#include</code>, then you don't
need the conditionals inside the header file to prevent multiple
inclusion of the contents. GCC permits the use of <code>#import</code> in C
and C++ as well as Objective-C. However, it is not in standard C or C++
and should therefore not be used by portable programs.
<p><code>#import</code> is not a well designed feature. It requires the users of
a header file to know that it should only be included once. It is much
better for the header file's implementor to write the file so that users
don't need to know this. Using a wrapper <code>#ifndef</code> accomplishes
this goal.
<p>In the present implementation, a single use of <code>#import</code> will
prevent the file from ever being read again, by either <code>#import</code> or
<code>#include</code>. You should not rely on this; do not use both
<code>#import</code> and <code>#include</code> to refer to the same header file.
<p>Another way to prevent a header file from being included more than once
is with the <code>#pragma once</code> directive. If <code>#pragma once</code> is
seen when scanning a header file, that file will never be read again, no
matter what.
<p><code>#pragma once</code> does not have the problems that <code>#import</code> does,
but it is not recognized by all preprocessors, so you cannot rely on it
in a portable program.
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -