source: public/doc/gnu-c/Undefining-and-Redefining-Macros.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 5.5 KB
Line 
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
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing 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<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.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>
60Next: <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> &nbsp; [<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
70undefine. You use the bare macro name, even if the macro is
71function-like. It is an error if anything appears on the line after
72the macro name. <code>#undef</code> has no effect if the name is not a
73macro.
74</p>
75<div class="example">
76<pre class="example">#define FOO 4
77x = FOO; &rarr; x = 4;
78#undef FOO
79x = FOO; &rarr; x = FOO;
80</pre></div>
81
82<p>Once a macro has been undefined, that identifier may be <em>redefined</em>
83as a macro by a subsequent <code>#define</code> directive. The new definition
84need not have any resemblance to the old definition.
85</p>
86<p>You can define a macro again without first undefining it only if
87the new definition is <em>effectively the same</em> as the old one.
88Two 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
95exactly the same amount of whitespace, though. Remember that comments
96count 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
116existing macro name with a different definition results in a warning.
117</p>
118<hr>
119<div class="header">
120<p>
121Next: <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> &nbsp; [<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>
Note: See TracBrowser for help on using the repository browser.