1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Undefining and Redefining Macros (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Undefining and Redefining Macros (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Undefining and Redefining Macros (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Macros.html" rel="up" title="Macros">
|
---|
33 | <link href="Directives-Within-Macro-Arguments.html" rel="next" title="Directives Within Macro Arguments">
|
---|
34 | <link href="Predefined-Macros.html" rel="prev" title="Predefined Macros">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Undefining-and-Redefining-Macros"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Directives-Within-Macro-Arguments.html" accesskey="n" rel="next">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html" accesskey="p" rel="prev">Predefined Macros</a>, Up: <a href="Macros.html" accesskey="u" rel="up">Macros</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Undefining-and-Redefining-Macros-1"></span><h4 class="subsection">26.5.8 Undefining and Redefining Macros</h4>
|
---|
64 | <span id="index-undefining-macros"></span>
|
---|
65 | <span id="index-redefining-macros"></span>
|
---|
66 | <span id="index-_0023undef"></span>
|
---|
67 |
|
---|
68 | <p>You can <em>undefine</em> a macro with the <code>#undef</code> directive.
|
---|
69 | <code>#undef</code> takes a single argument, the name of the macro to
|
---|
70 | undefine. You use the bare macro name, even if the macro is
|
---|
71 | function-like. It is an error if anything appears on the line after
|
---|
72 | the macro name. <code>#undef</code> has no effect if the name is not a
|
---|
73 | macro.
|
---|
74 | </p>
|
---|
75 | <div class="example">
|
---|
76 | <pre class="example">#define FOO 4
|
---|
77 | x = FOO; → x = 4;
|
---|
78 | #undef FOO
|
---|
79 | x = FOO; → x = FOO;
|
---|
80 | </pre></div>
|
---|
81 |
|
---|
82 | <p>Once a macro has been undefined, that identifier may be <em>redefined</em>
|
---|
83 | as a macro by a subsequent <code>#define</code> directive. The new definition
|
---|
84 | need not have any resemblance to the old definition.
|
---|
85 | </p>
|
---|
86 | <p>You can define a macro again without first undefining it only if
|
---|
87 | the new definition is <em>effectively the same</em> as the old one.
|
---|
88 | Two macro definitions are effectively the same if:
|
---|
89 | </p>
|
---|
90 | <ul>
|
---|
91 | <li> Both are the same type of macro (object- or function-like).
|
---|
92 | </li><li> All the tokens of the replacement list are the same.
|
---|
93 | </li><li> If there are any parameters, they are the same.
|
---|
94 | </li><li> Whitespace appears in the same places in both. It need not be
|
---|
95 | exactly the same amount of whitespace, though. Remember that comments
|
---|
96 | count as whitespace.
|
---|
97 | </li></ul>
|
---|
98 |
|
---|
99 | <p>These definitions are effectively the same:
|
---|
100 | </p><div class="example">
|
---|
101 | <pre class="example">#define FOUR (2 + 2)
|
---|
102 | #define FOUR (2 + 2)
|
---|
103 | #define FOUR (2 /* <span class="roman">two</span> */ + 2)
|
---|
104 | </pre></div>
|
---|
105 | <p>but these are not:
|
---|
106 | </p><div class="example">
|
---|
107 | <pre class="example">#define FOUR (2 + 2)
|
---|
108 | #define FOUR ( 2+2 )
|
---|
109 | #define FOUR (2 * 2)
|
---|
110 | #define FOUR(score,and,seven,years,ago) (2 + 2)
|
---|
111 | </pre></div>
|
---|
112 |
|
---|
113 | <p>This allows two different header files to define a common macro.
|
---|
114 | </p>
|
---|
115 | <p>You can redefine an existing macro with #define, but redefining an
|
---|
116 | existing macro name with a different definition results in a warning.
|
---|
117 | </p>
|
---|
118 | <hr>
|
---|
119 | <div class="header">
|
---|
120 | <p>
|
---|
121 | Next: <a href="Directives-Within-Macro-Arguments.html" accesskey="n" rel="next">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html" accesskey="p" rel="prev">Predefined Macros</a>, Up: <a href="Macros.html" accesskey="u" rel="up">Macros</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
122 | </div>
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | </body>
|
---|
127 | </html>
|
---|