source: public/doc/gnu-c/Preprocessing-Tokens.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: 8.2 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>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<!--
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="Preprocessing-Tokens"></span><div class="header">
59<p>
60Next: <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> &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="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.
68Here are the quirks of preprocessing tokens.
69</p>
70<p>The main classes of preprocessing tokens are identifiers,
71preprocessing numbers, string constants, character constants, and
72punctuators; 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
78identifier in C: any sequence of letters, digits, or underscores, as
79well as non-ASCII characters represented using &lsquo;<samp>\U</samp>&rsquo; or &lsquo;<samp>\u</samp>&rsquo;,
80that doesn&rsquo;t begin with a digit.
81</p>
82<p>During preprocessing, the keywords of C have no special significance;
83at that stage, they are simply identifiers. Thus, you can define a
84macro whose name is a keyword. The only identifier that is special
85during 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
92textually as a number, including C numeric constants, and other
93sequences of characters which resemble numeric constants.
94Preprocessing does not try to verify that a preprocessing number is a
95valid number in C, and indeed it need not be one.
96</p>
97<p>More precisely, preprocessing numbers begin with an optional period, a
98required decimal digit, and then continue with any sequence of
99letters, digits, underscores, periods, and exponents. Exponents are
100the two-character sequences &lsquo;<samp>e+</samp>&rsquo;, &lsquo;<samp>e-</samp>&rsquo;, &lsquo;<samp>E+</samp>&rsquo;,
101&lsquo;<samp>E-</samp>&rsquo;, &lsquo;<samp>p+</samp>&rsquo;, &lsquo;<samp>p-</samp>&rsquo;, &lsquo;<samp>P+</samp>&rsquo;, and &lsquo;<samp>P-</samp>&rsquo;. (The
102exponents that begin with &lsquo;<samp>p</samp>&rsquo; or &lsquo;<samp>P</samp>&rsquo; are new to C99. They
103are used for hexadecimal floating-point constants.)
104</p>
105<p>The reason behind this unusual syntactic class is that the full
106complexity of numeric constants is irrelevant during preprocessing.
107The distinction between lexically valid and invalid floating-point
108numbers, for example, doesn&rsquo;t matter at this stage. The use of
109preprocessing numbers makes it possible to split an identifier at any
110position and get exactly two tokens, and reliably paste them together
111using 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.
116These are the valid punctuators:
117</p>
118<div class="example">
119<pre class="example">[ ] ( ) { } . -&gt;
120++ -- &amp; * + - ~ !
121/ % &lt;&lt; &gt;&gt; &lt; &gt; &lt;= &gt;= == != ^ | &amp;&amp; ||
122? : ; ...
123= *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=
124, # ##
125&lt;: :&gt; &lt;% %&gt; %: %:%:
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
131a 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
136as 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 &lsquo;<samp>&quot;<var>name</var>&quot;</samp>&rsquo;, where
142<var>name</var> is a sequence of source characters other than newline and
143&lsquo;<samp>&quot;</samp>&rsquo;, or &lsquo;<samp>&lt;<var>name</var>&gt;</samp>&rsquo;, where <var>name</var> is a sequence of
144source characters other than newline and &lsquo;<samp>&gt;</samp>&rsquo;.
145</p>
146<p>In practice, it is more convenient to think that the <code>#include</code> line
147is exempt from tokenization.
148</p>
149</dd>
150<dt>other</dt>
151<dd><p>Any other character that&rsquo;s valid in a C source program
152is treated as a separate preprocessing token.
153</p></dd>
154</dl>
155
156<p>Once the program is broken into preprocessing tokens, they remain
157separate until the end of preprocessing. Macros that generate two
158consecutive tokens insert whitespace to keep them separate, if
159necessary. For example,
160</p>
161<div class="example">
162<pre class="example">#define foo() bar
163foo()baz
164 &rarr; bar baz
165<em>not</em>
166 &rarr; barbaz
167</pre></div>
168
169<p>The only exception is with the <code>##</code> preprocessing operator, which
170pastes tokens together (see <a href="Concatenation.html">Concatenation</a>).
171</p>
172<p>Preprocessing treats the null character (code 0) as whitespace, but
173generates 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
175is probably a mistake.
176</p>
177<hr>
178<div class="header">
179<p>
180Next: <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> &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>
181</div>
182
183
184
185</body>
186</html>
Note: See TracBrowser for help on using the repository browser.