• 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>Traditional 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="Traditional-Mode.html#Traditional-Mode" title="Traditional Mode">
9<link rel="prev" href="Traditional-lexical-analysis.html#Traditional-lexical-analysis" title="Traditional lexical analysis">
10<link rel="next" href="Traditional-miscellany.html#Traditional-miscellany" title="Traditional miscellany">
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="Traditional-macros"></a>
54<p>
55Next:&nbsp;<a rel="next" accesskey="n" href="Traditional-miscellany.html#Traditional-miscellany">Traditional miscellany</a>,
56Previous:&nbsp;<a rel="previous" accesskey="p" href="Traditional-lexical-analysis.html#Traditional-lexical-analysis">Traditional lexical analysis</a>,
57Up:&nbsp;<a rel="up" accesskey="u" href="Traditional-Mode.html#Traditional-Mode">Traditional Mode</a>
58<hr>
59</div>
60
61<h3 class="section">10.2 Traditional macros</h3>
62
63<p>The major difference between traditional and ISO macros is that the
64former expand to text rather than to a token sequence.  CPP removes
65all leading and trailing horizontal whitespace from a macro's
66replacement text before storing it, but preserves the form of internal
67whitespace.
68
69   <p>One consequence is that it is legitimate for the replacement text to
70contain an unmatched quote (see <a href="Traditional-lexical-analysis.html#Traditional-lexical-analysis">Traditional lexical analysis</a>).  An
71unclosed string or character constant continues into the text
72following the macro call.  Similarly, the text at the end of a macro's
73expansion can run together with the text after the macro invocation to
74produce a single token.
75
76   <p>Normally comments are removed from the replacement text after the
77macro is expanded, but if the <samp><span class="option">-CC</span></samp> option is passed on the
78command line comments are preserved.  (In fact, the current
79implementation removes comments even before saving the macro
80replacement text, but it careful to do it in such a way that the
81observed effect is identical even in the function-like macro case.)
82
83   <p>The ISO stringification operator &lsquo;<samp><span class="samp">#</span></samp>&rsquo; and token paste operator
84&lsquo;<samp><span class="samp">##</span></samp>&rsquo; have no special meaning.  As explained later, an effect
85similar to these operators can be obtained in a different way.  Macro
86names that are embedded in quotes, either from the main file or after
87macro replacement, do not expand.
88
89   <p>CPP replaces an unquoted object-like macro name with its replacement
90text, and then rescans it for further macros to replace.  Unlike
91standard macro expansion, traditional macro expansion has no provision
92to prevent recursion.  If an object-like macro appears unquoted in its
93replacement text, it will be replaced again during the rescan pass,
94and so on <em>ad infinitum</em>.  GCC detects when it is expanding
95recursive macros, emits an error message, and continues after the
96offending macro invocation.
97
98<pre class="smallexample">     #define PLUS +
99     #define INC(x) PLUS+x
100     INC(foo);
101          ==&gt; ++foo;
102</pre>
103   <p>Function-like macros are similar in form but quite different in
104behavior to their ISO counterparts.  Their arguments are contained
105within parentheses, are comma-separated, and can cross physical lines. 
106Commas within nested parentheses are not treated as argument
107separators.  Similarly, a quote in an argument cannot be left
108unclosed; a following comma or parenthesis that comes before the
109closing quote is treated like any other character.  There is no
110facility for handling variadic macros.
111
112   <p>This implementation removes all comments from macro arguments, unless
113the <samp><span class="option">-C</span></samp> option is given.  The form of all other horizontal
114whitespace in arguments is preserved, including leading and trailing
115whitespace.  In particular
116
117<pre class="smallexample">     f( )
118</pre>
119   <p class="noindent">is treated as an invocation of the macro &lsquo;<samp><span class="samp">f</span></samp>&rsquo; with a single
120argument consisting of a single space.  If you want to invoke a
121function-like macro that takes no arguments, you must not leave any
122whitespace between the parentheses.
123
124   <p>If a macro argument crosses a new line, the new line is replaced with
125a space when forming the argument.  If the previous line contained an
126unterminated quote, the following line inherits the quoted state.
127
128   <p>Traditional preprocessors replace parameters in the replacement text
129with their arguments regardless of whether the parameters are within
130quotes or not.  This provides a way to stringize arguments.  For
131example
132
133<pre class="smallexample">     #define str(x) "x"
134     str(/* <span class="roman">A comment</span> */some text )
135          ==&gt; "some text "
136</pre>
137   <p class="noindent">Note that the comment is removed, but that the trailing space is
138preserved.  Here is an example of using a comment to effect token
139pasting.
140
141<pre class="smallexample">     #define suffix(x) foo_/**/x
142     suffix(bar)
143          ==&gt; foo_bar
144</pre>
145   </body></html>
146
147