⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 undefining-and-redefining-macros.html

📁 gcc手册
💻 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 &copy; 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="Undefining%20and%20Redefining%20Macros">Undefining and Redefining Macros</a>,

Next:<a rel="next" accesskey="n" href="Directives-Within-Macro-Arguments.html#Directives%20Within%20Macro%20Arguments">Directives Within Macro Arguments</a>,

Previous:<a rel="previous" accesskey="p" href="Predefined-Macros.html#Predefined%20Macros">Predefined Macros</a>,

Up:<a rel="up" accesskey="u" href="Macros.html#Macros">Macros</a>

<hr><br>

</div>



<h3 class="section">Undefining and Redefining Macros</h3>



   <p>If a macro ceases to be useful, it may be <dfn>undefined</dfn> with the

<code>#undef</code> directive.  <code>#undef</code> takes a single argument, the

name of the macro to undefine.  You use the bare macro name, even if the

macro is function-like.  It is an error if anything appears on the line

after the macro name.  <code>#undef</code> has no effect if the name is not a

macro.



<pre class="example">     #define FOO 4

     x = FOO;        ==&gt; x = 4;

     #undef FOO

     x = FOO;        ==&gt; x = FOO;

     </pre>



   <p>Once a macro has been undefined, that identifier may be <dfn>redefined</dfn>

as a macro by a subsequent <code>#define</code> directive.  The new definition

need not have any resemblance to the old definition.



   <p>However, if an identifier which is currently a macro is redefined, then

the new definition must be <dfn>effectively the same</dfn> as the old one. 

Two macro definitions are effectively the same if:

     <ul>

<li>Both are the same type of macro (object- or function-like). 

<li>All the tokens of the replacement list are the same. 

<li>If there are any parameters, they are the same. 

<li>Whitespace appears in the same places in both.  It need not be

exactly the same amount of whitespace, though.  Remember that comments

count as whitespace. 

</ul>



<p>These definitions are effectively the same:

<pre class="example">     #define FOUR (2 + 2)

     #define FOUR         (2    +    2)

     #define FOUR (2 /* two */ + 2)

     </pre>



<p>but these are not:

<pre class="example">     #define FOUR (2 + 2)

     #define FOUR ( 2+2 )

     #define FOUR (2 * 2)

     #define FOUR(score,and,seven,years,ago) (2 + 2)

     </pre>



   <p>If a macro is redefined with a definition that is not effectively the

same as the old one, the preprocessor issues a warning and changes the

macro to use the new definition.  If the new definition is effectively

the same, the redefinition is silently ignored.  This allows, for

instance, two different headers to define a common macro.  The

preprocessor will only complain if the definitions do not match.



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -