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>Preprocessing Tokens (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Preprocessing Tokens (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Preprocessing Tokens (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="Preprocessing.html" rel="up" title="Preprocessing">
|
---|
33 | <link href="Header-Files.html" rel="next" title="Header Files">
|
---|
34 | <link href="Directives.html" rel="prev" title="Directives">
|
---|
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="Preprocessing-Tokens"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Header-Files.html" accesskey="n" rel="next">Header Files</a>, Previous: <a href="Directives.html" accesskey="p" rel="prev">Directives</a>, Up: <a href="Preprocessing.html" accesskey="u" rel="up">Preprocessing</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="Preprocessing-Tokens-1"></span><h3 class="section">26.3 Preprocessing Tokens</h3>
|
---|
64 |
|
---|
65 | <span id="index-preprocessing-tokens"></span>
|
---|
66 | <p>Preprocessing divides C code (minus its comments) into
|
---|
67 | <em>tokens</em> that are similar to C tokens, but not exactly the same.
|
---|
68 | Here are the quirks of preprocessing tokens.
|
---|
69 | </p>
|
---|
70 | <p>The main classes of preprocessing tokens are identifiers,
|
---|
71 | preprocessing numbers, string constants, character constants, and
|
---|
72 | punctuators; there are a few others too.
|
---|
73 | </p>
|
---|
74 | <dl compact="compact">
|
---|
75 | <dt>identifier</dt>
|
---|
76 | <dd><span id="index-identifiers-1"></span>
|
---|
77 | <p>An <em>identifier</em> preprocessing token is syntactically like an
|
---|
78 | identifier in C: any sequence of letters, digits, or underscores, as
|
---|
79 | well as non-ASCII characters represented using ‘<samp>\U</samp>’ or ‘<samp>\u</samp>’,
|
---|
80 | that doesn’t begin with a digit.
|
---|
81 | </p>
|
---|
82 | <p>During preprocessing, the keywords of C have no special significance;
|
---|
83 | at that stage, they are simply identifiers. Thus, you can define a
|
---|
84 | macro whose name is a keyword. The only identifier that is special
|
---|
85 | during preprocessing is <code>defined</code> (see <a href="defined.html">defined</a>).
|
---|
86 | </p>
|
---|
87 | </dd>
|
---|
88 | <dt>preprocessing number</dt>
|
---|
89 | <dd><span id="index-numbers_002c-preprocessing"></span>
|
---|
90 | <span id="index-preprocessing-numbers"></span>
|
---|
91 | <p>A <em>preprocessing number</em> is something that preprocessing treats
|
---|
92 | textually as a number, including C numeric constants, and other
|
---|
93 | sequences of characters which resemble numeric constants.
|
---|
94 | Preprocessing does not try to verify that a preprocessing number is a
|
---|
95 | valid number in C, and indeed it need not be one.
|
---|
96 | </p>
|
---|
97 | <p>More precisely, preprocessing numbers begin with an optional period, a
|
---|
98 | required decimal digit, and then continue with any sequence of
|
---|
99 | letters, digits, underscores, periods, and exponents. Exponents are
|
---|
100 | the two-character sequences ‘<samp>e+</samp>’, ‘<samp>e-</samp>’, ‘<samp>E+</samp>’,
|
---|
101 | ‘<samp>E-</samp>’, ‘<samp>p+</samp>’, ‘<samp>p-</samp>’, ‘<samp>P+</samp>’, and ‘<samp>P-</samp>’. (The
|
---|
102 | exponents that begin with ‘<samp>p</samp>’ or ‘<samp>P</samp>’ are new to C99. They
|
---|
103 | are used for hexadecimal floating-point constants.)
|
---|
104 | </p>
|
---|
105 | <p>The reason behind this unusual syntactic class is that the full
|
---|
106 | complexity of numeric constants is irrelevant during preprocessing.
|
---|
107 | The distinction between lexically valid and invalid floating-point
|
---|
108 | numbers, for example, doesn’t matter at this stage. The use of
|
---|
109 | preprocessing numbers makes it possible to split an identifier at any
|
---|
110 | position and get exactly two tokens, and reliably paste them together
|
---|
111 | using the <code>##</code> operator (see <a href="Concatenation.html">Concatenation</a>).
|
---|
112 | </p>
|
---|
113 | </dd>
|
---|
114 | <dt>punctuator</dt>
|
---|
115 | <dd><p>A <em>punctuator</em> is syntactically like an operator.
|
---|
116 | These are the valid punctuators:
|
---|
117 | </p>
|
---|
118 | <div class="example">
|
---|
119 | <pre class="example">[ ] ( ) { } . ->
|
---|
120 | ++ -- & * + - ~ !
|
---|
121 | / % << >> < > <= >= == != ^ | && ||
|
---|
122 | ? : ; ...
|
---|
123 | = *= /= %= += -= <<= >>= &= ^= |=
|
---|
124 | , # ##
|
---|
125 | <: :> <% %> %: %:%:
|
---|
126 | </pre></div>
|
---|
127 |
|
---|
128 | </dd>
|
---|
129 | <dt>string constant</dt>
|
---|
130 | <dd><p>A string constant in the source code is recognized by preprocessing as
|
---|
131 | a single preprocessing token.
|
---|
132 | </p>
|
---|
133 | </dd>
|
---|
134 | <dt>character constant</dt>
|
---|
135 | <dd><p>A character constant in the source code is recognized by preprocessing
|
---|
136 | as a single preprocessing token.
|
---|
137 | </p>
|
---|
138 | </dd>
|
---|
139 | <dt>header name</dt>
|
---|
140 | <dd><p>Within the <code>#include</code> directive, preprocessing recognizes a
|
---|
141 | <em>header name</em> token. It consists of ‘<samp>"<var>name</var>"</samp>’, where
|
---|
142 | <var>name</var> is a sequence of source characters other than newline and
|
---|
143 | ‘<samp>"</samp>’, or ‘<samp><<var>name</var>></samp>’, where <var>name</var> is a sequence of
|
---|
144 | source characters other than newline and ‘<samp>></samp>’.
|
---|
145 | </p>
|
---|
146 | <p>In practice, it is more convenient to think that the <code>#include</code> line
|
---|
147 | is exempt from tokenization.
|
---|
148 | </p>
|
---|
149 | </dd>
|
---|
150 | <dt>other</dt>
|
---|
151 | <dd><p>Any other character that’s valid in a C source program
|
---|
152 | is treated as a separate preprocessing token.
|
---|
153 | </p></dd>
|
---|
154 | </dl>
|
---|
155 |
|
---|
156 | <p>Once the program is broken into preprocessing tokens, they remain
|
---|
157 | separate until the end of preprocessing. Macros that generate two
|
---|
158 | consecutive tokens insert whitespace to keep them separate, if
|
---|
159 | necessary. For example,
|
---|
160 | </p>
|
---|
161 | <div class="example">
|
---|
162 | <pre class="example">#define foo() bar
|
---|
163 | foo()baz
|
---|
164 | → bar baz
|
---|
165 | <em>not</em>
|
---|
166 | → barbaz
|
---|
167 | </pre></div>
|
---|
168 |
|
---|
169 | <p>The only exception is with the <code>##</code> preprocessing operator, which
|
---|
170 | pastes tokens together (see <a href="Concatenation.html">Concatenation</a>).
|
---|
171 | </p>
|
---|
172 | <p>Preprocessing treats the null character (code 0) as whitespace, but
|
---|
173 | generates a warning for it because it may be invisible to the user
|
---|
174 | (many terminals do not display it at all) and its presence in the file
|
---|
175 | is probably a mistake.
|
---|
176 | </p>
|
---|
177 | <hr>
|
---|
178 | <div class="header">
|
---|
179 | <p>
|
---|
180 | Next: <a href="Header-Files.html" accesskey="n" rel="next">Header Files</a>, Previous: <a href="Directives.html" accesskey="p" rel="prev">Directives</a>, Up: <a href="Preprocessing.html" accesskey="u" rel="up">Preprocessing</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>
|
---|
181 | </div>
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | </body>
|
---|
186 | </html>
|
---|