• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/share/doc/arm-arm-none-eabi/html/cpp/
1<html lang="en">
2<head>
3<title>Undefining and Redefining Macros - The C Preprocessor</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="The C Preprocessor">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Macros.html#Macros" title="Macros">
9<link rel="prev" href="Predefined-Macros.html#Predefined-Macros" title="Predefined Macros">
10<link rel="next" href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments" title="Directives Within Macro Arguments">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
141997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
152008, 2009, 2010, 2011
16Free Software Foundation, Inc.
17
18Permission is granted to copy, distribute and/or modify this document
19under the terms of the GNU Free Documentation License, Version 1.3 or
20any later version published by the Free Software Foundation.  A copy of
21the license is included in the
22section entitled ``GNU Free Documentation License''.
23
24This manual contains no Invariant Sections.  The Front-Cover Texts are
25(a) (see below), and the Back-Cover Texts are (b) (see below).
26
27(a) The FSF's Front-Cover Text is:
28
29     A GNU Manual
30
31(b) The FSF's Back-Cover Text is:
32
33     You have freedom to copy and modify this GNU Manual, like GNU
34     software.  Copies published by the Free Software Foundation raise
35     funds for GNU development.
36-->
37<meta http-equiv="Content-Style-Type" content="text/css">
38<style type="text/css"><!--
39  pre.display { font-family:inherit }
40  pre.format  { font-family:inherit }
41  pre.smalldisplay { font-family:inherit; font-size:smaller }
42  pre.smallformat  { font-family:inherit; font-size:smaller }
43  pre.smallexample { font-size:smaller }
44  pre.smalllisp    { font-size:smaller }
45  span.sc    { font-variant:small-caps }
46  span.roman { font-family:serif; font-weight:normal; } 
47  span.sansserif { font-family:sans-serif; font-weight:normal; } 
48--></style>
49<link rel="stylesheet" type="text/css" href="../cs.css">
50</head>
51<body>
52<div class="node">
53<a name="Undefining-and-Redefining-Macros"></a>
54<p>
55Next:&nbsp;<a rel="next" accesskey="n" href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments">Directives Within Macro Arguments</a>,
56Previous:&nbsp;<a rel="previous" accesskey="p" href="Predefined-Macros.html#Predefined-Macros">Predefined Macros</a>,
57Up:&nbsp;<a rel="up" accesskey="u" href="Macros.html#Macros">Macros</a>
58<hr>
59</div>
60
61<h3 class="section">3.8 Undefining and Redefining Macros</h3>
62
63<p><a name="index-undefining-macros-68"></a><a name="index-redefining-macros-69"></a><a name="index-g_t_0023undef-70"></a>
64If a macro ceases to be useful, it may be <dfn>undefined</dfn> with the
65&lsquo;<samp><span class="samp">#undef</span></samp>&rsquo; directive.  &lsquo;<samp><span class="samp">#undef</span></samp>&rsquo; takes a single argument, the
66name of the macro to undefine.  You use the bare macro name, even if the
67macro is function-like.  It is an error if anything appears on the line
68after the macro name.  &lsquo;<samp><span class="samp">#undef</span></samp>&rsquo; has no effect if the name is not a
69macro.
70
71<pre class="smallexample">     #define FOO 4
72     x = FOO;        ==&gt; x = 4;
73     #undef FOO
74     x = FOO;        ==&gt; x = FOO;
75</pre>
76   <p>Once a macro has been undefined, that identifier may be <dfn>redefined</dfn>
77as a macro by a subsequent &lsquo;<samp><span class="samp">#define</span></samp>&rsquo; directive.  The new definition
78need not have any resemblance to the old definition.
79
80   <p>However, if an identifier which is currently a macro is redefined, then
81the new definition must be <dfn>effectively the same</dfn> as the old one. 
82Two macro definitions are effectively the same if:
83     <ul>
84<li>Both are the same type of macro (object- or function-like). 
85<li>All the tokens of the replacement list are the same. 
86<li>If there are any parameters, they are the same. 
87<li>Whitespace appears in the same places in both.  It need not be
88exactly the same amount of whitespace, though.  Remember that comments
89count as whitespace. 
90</ul>
91
92<p class="noindent">These definitions are effectively the same:
93<pre class="smallexample">     #define FOUR (2 + 2)
94     #define FOUR         (2    +    2)
95     #define FOUR (2 /* <span class="roman">two</span> */ + 2)
96</pre>
97   <p class="noindent">but these are not:
98<pre class="smallexample">     #define FOUR (2 + 2)
99     #define FOUR ( 2+2 )
100     #define FOUR (2 * 2)
101     #define FOUR(score,and,seven,years,ago) (2 + 2)
102</pre>
103   <p>If a macro is redefined with a definition that is not effectively the
104same as the old one, the preprocessor issues a warning and changes the
105macro to use the new definition.  If the new definition is effectively
106the same, the redefinition is silently ignored.  This allows, for
107instance, two different headers to define a common macro.  The
108preprocessor will only complain if the definitions do not match.
109
110   </body></html>
111
112