blob: 502b421176696184fa09f9817dc2625e782a2268 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1987-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 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".
This manual contains no Invariant Sections. The Front-Cover Texts are
(a) (see below), and the Back-Cover Texts are (b) (see below).
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
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. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>The C Preprocessor: Undefining and Redefining Macros</title>
<meta name="description" content="The C Preprocessor: Undefining and Redefining Macros">
<meta name="keywords" content="The C Preprocessor: Undefining and Redefining Macros">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Macros.html#Macros" rel="up" title="Macros">
<link href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments" rel="next" title="Directives Within Macro Arguments">
<link href="C_002b_002b-Named-Operators.html#C_002b_002b-Named-Operators" rel="prev" title="C++ Named Operators">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Undefining-and-Redefining-Macros"></a>
<div class="header">
<p>
Next: <a href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments" accesskey="n" rel="next">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html#Predefined-Macros" accesskey="p" rel="prev">Predefined Macros</a>, Up: <a href="Macros.html#Macros" accesskey="u" rel="up">Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Undefining-and-Redefining-Macros-1"></a>
<h3 class="section">3.8 Undefining and Redefining Macros</h3>
<a name="index-undefining-macros"></a>
<a name="index-redefining-macros"></a>
<a name="index-_0023undef"></a>
<p>If a macro ceases to be useful, it may be <em>undefined</em> with the
&lsquo;<samp>#undef</samp>&rsquo; directive. &lsquo;<samp>#undef</samp>&rsquo; 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. &lsquo;<samp>#undef</samp>&rsquo; has no effect if the name is not a
macro.
</p>
<div class="smallexample">
<pre class="smallexample">#define FOO 4
x = FOO; &rarr; x = 4;
#undef FOO
x = FOO; &rarr; x = FOO;
</pre></div>
<p>Once a macro has been undefined, that identifier may be <em>redefined</em>
as a macro by a subsequent &lsquo;<samp>#define</samp>&rsquo; directive. The new definition
need not have any resemblance to the old definition.
</p>
<p>However, if an identifier which is currently a macro is redefined, then
the new definition must be <em>effectively the same</em> as the old one.
Two macro definitions are effectively the same if:
</p><ul>
<li> Both are the same type of macro (object- or function-like).
</li><li> All the tokens of the replacement list are the same.
</li><li> If there are any parameters, they are the same.
</li><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.
</li></ul>
<p>These definitions are effectively the same:
</p><div class="smallexample">
<pre class="smallexample">#define FOUR (2 + 2)
#define FOUR (2 + 2)
#define FOUR (2 /* <span class="roman">two</span> */ + 2)
</pre></div>
<p>but these are not:
</p><div class="smallexample">
<pre class="smallexample">#define FOUR (2 + 2)
#define FOUR ( 2+2 )
#define FOUR (2 * 2)
#define FOUR(score,and,seven,years,ago) (2 + 2)
</pre></div>
<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.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments" accesskey="n" rel="next">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html#Predefined-Macros" accesskey="p" rel="prev">Predefined Macros</a>, Up: <a href="Macros.html#Macros" accesskey="u" rel="up">Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>