• 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>Directives Within Macro Arguments - 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="Undefining-and-Redefining-Macros.html#Undefining-and-Redefining-Macros" title="Undefining and Redefining Macros">
10<link rel="next" href="Macro-Pitfalls.html#Macro-Pitfalls" title="Macro Pitfalls">
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="Directives-Within-Macro-Arguments"></a>
54<p>
55Next:&nbsp;<a rel="next" accesskey="n" href="Macro-Pitfalls.html#Macro-Pitfalls">Macro Pitfalls</a>,
56Previous:&nbsp;<a rel="previous" accesskey="p" href="Undefining-and-Redefining-Macros.html#Undefining-and-Redefining-Macros">Undefining and Redefining 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.9 Directives Within Macro Arguments</h3>
62
63<p><a name="index-macro-arguments-and-directives-71"></a>
64Occasionally it is convenient to use preprocessor directives within
65the arguments of a macro.  The C and C++ standards declare that
66behavior in these cases is undefined.
67
68   <p>Versions of CPP prior to 3.2 would reject such constructs with an
69error message.  This was the only syntactic difference between normal
70functions and function-like macros, so it seemed attractive to remove
71this limitation, and people would often be surprised that they could
72not use macros in this way.  Moreover, sometimes people would use
73conditional compilation in the argument list to a normal library
74function like &lsquo;<samp><span class="samp">printf</span></samp>&rsquo;, only to find that after a library upgrade
75&lsquo;<samp><span class="samp">printf</span></samp>&rsquo; had changed to be a function-like macro, and their code
76would no longer compile.  So from version 3.2 we changed CPP to
77successfully process arbitrary directives within macro arguments in
78exactly the same way as it would have processed the directive were the
79function-like macro invocation not present.
80
81   <p>If, within a macro invocation, that macro is redefined, then the new
82definition takes effect in time for argument pre-expansion, but the
83original definition is still used for argument replacement.  Here is a
84pathological example:
85
86<pre class="smallexample">     #define f(x) x x
87     f (1
88     #undef f
89     #define f 2
90     f)
91</pre>
92   <p class="noindent">which expands to
93
94<pre class="smallexample">     1 2 1 2
95</pre>
96   <p class="noindent">with the semantics described above.
97
98   </body></html>
99
100