1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<h1 id="firstHeading" class="firstHeading">Identifier</h1> <p>An <i>identifier</i> is an arbitrarily long sequence of digits, underscores, lowercase and uppercase Latin letters<span class="t-rev-inl t-since-c99"><span>, and Unicode characters specified using <code>\u</code> and <code>\U</code> <a href="escape" title="c/language/escape">escape</a> notation</span><span><span class="t-mark-rev t-since-c99">(since C99)</span></span></span><span class="t-rev-inl t-since-c23"><span>, of class <a rel="nofollow" class="external text" href="https://www.unicode.org/reports/tr31/#Table_Lexical_Classes_for_Identifiers">XID_Continue</a></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>. A valid identifier must begin with a non-digit character (Latin letter, underscore<span class="t-rev-inl t-since-c99 t-until-c23"><span>, or Unicode non-digit character</span><span><span class="t-mark-rev t-since-c99">(since C99)</span><span class="t-mark-rev t-until-c23">(until C23)</span></span></span><span class="t-rev-inl t-since-c23"><span>, or Unicode character of class <a rel="nofollow" class="external text" href="https://www.unicode.org/reports/tr31/#Table_Lexical_Classes_for_Identifiers">XID_Start</a>)</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>). Identifiers are case-sensitive (lowercase and uppercase letters are distinct). <span class="t-rev-inl t-since-c23"><span>Every identifier must conform to <a rel="nofollow" class="external text" href="https://www.unicode.org/charts/normalization/">Normalization Form C</a>.</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span></p>
<table class="t-rev-begin"> <tr class="t-rev t-since-c99 t-until-c23">
<td>It is implementation-defined if raw (not escaped) Unicode characters are allowed in identifiers: <div class="c source-c"><pre data-language="c">char *\U0001f431 = "cat"; // supported
char *🐱 = "cat"; // implementation-defined
// (e.g. works with Clang, but not GCC prior to version 10)
// both are ill formed in C23. Emoji are not XID_Start characters</pre></div> </td> <td>
<span class="t-mark-rev t-since-c99">(since C99)</span><br><span class="t-mark-rev t-until-c23">(until C23)</span>
</td>
</tr> <tr class="t-rev t-since-c23">
<td>Implementation-defined characters whose corresponding code points in <a rel="nofollow" class="external text" href="https://unicode.org/L2/L2010/10038-fcd10646-main.pdf">ISO/IEC 10646</a> (Unicode) have the XID_Start or XID_Continue property can appear in the beginning or after the first character of an identifier respectively.</td> <td><span class="t-mark-rev t-since-c23">(since C23)</span></td>
</tr> </table> <p>Identifiers can denote the following types of entities:</p>
<ul>
<li> <a href="object" title="c/language/object">objects</a> </li>
<li> <a href="functions" title="c/language/functions">functions</a> </li>
<li> tags (<a href="struct" title="c/language/struct">struct</a>, <a href="union" title="c/language/union">union</a>, or <a href="enum" title="c/language/enum">enumerations</a>) </li>
<li> structure or union members </li>
<li> enumeration constants </li>
<li> <a href="typedef" title="c/language/typedef">typedef</a> names </li>
<li> <a href="statements#Labels" title="c/language/statements">label</a> names </li>
<li> <a href="../preprocessor/replace" title="c/preprocessor/replace">macro</a> names </li>
<li> <a href="../preprocessor/replace" title="c/preprocessor/replace">macro parameter</a> names </li>
</ul> <p>Every identifier other than macro names or macro parameter names has <a href="scope" title="c/language/scope">scope</a>, belongs to a <a href="name_space" title="c/language/name space">name space</a>, and may have <a href="storage_duration" title="c/language/storage duration">linkage</a>. The same identifier can denote different entities at different points in the program, or may denote different entities at the same point if the entities are in different name spaces.</p>
<h3 id="Reserved_identifiers"> Reserved identifiers</h3> <p>The following identifiers are <i>reserved</i> and may not be declared in a program (doing so invokes undefined behavior):</p>
<ol> <li>The identifiers that are <a href="../keyword" title="c/keyword">keywords</a> cannot be used for other purposes. In particular #define or #undef of an identifier that is identical to a keyword is not allowed.</li> <li>All external identifiers that begin with an underscore.</li> <li>All identifiers that begin with an underscore followed by a capital letter or by another underscore (these reserved identifiers allow the library to use numerous behind-the-scenes non-external macros and functions).</li> <li>All external identifiers defined by the standard library (in hosted environment). This means that no user-supplied external names are allowed to match any library names, not even if declaring a function that is identical to a library function.</li> <li>Identifiers declared as reserved for the implementation or future use by the standard library (see below).</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c23">
<span>Identifiers declared as potentially reserved and provided by the implementation (see below).</span> <span class="t-mark-rev t-since-c23">(since C23)</span>
</li> </ol> <p>All other identifiers are available. Identifiers that are not reserved <span class="t-rev-inl t-since-c23"><span>or potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> can be used with no fear of unexpected collisions when moving programs from one compiler and library to another.</p>
<p>Note: in C++, identifiers with a double underscore anywhere are reserved everywhere; in C, only the ones that begin with a double underscore are reserved.</p>
<h4 id="Reserved_and_potentially_reserved_identifiers_in_the_library"> Reserved and potentially reserved identifiers in the library</h4> <p>The standard library reserves every identifier it provides. Reserved identifiers that have <a href="storage_duration" title="c/language/storage duration">external linkage</a> (e.g. name of every standard function) are reserved regardless which header is included. Other reserved identifiers are reserved when any of its associated headers is included.</p>
<table class="t-rev-begin"> <tr class="t-rev t-since-c23">
<td> <p>Potentially reserved identifiers are intended to be used by the implementation and future revision of standard. If a potentially reserved identifier is provided by the implementation, it becomes reserved.</p>
<p>Implementations are only allowed to provide <a href="extern" title="c/language/extern">external definitions</a> of potentially reserved identifiers that are reserved as function names.</p>
<p>Potentially reserved identifiers that are not provided by the implementation are not reserved. They can be declared or defined by the user without undefined behavior. However, such usage is not portable.</p>
</td> <td><span class="t-mark-rev t-since-c23">(since C23)</span></td>
</tr> </table> <p>Following identifiers are reserved <span class="t-rev-inl t-since-c23"><span>or potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> for the implementation or future use by the standard library.</p>
<ul> <li>
<i>function names</i><span class="t-rev-inl t-since-c23"><span>, all of which are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> <ul> <li class="t-rev-inl t-rev-inl-noborder t-since-c99">
<span><code>cerf</code>, <code>cerfc</code>, <code>cexp2</code>, <code>cexpm1</code>, <code>clog10</code>, <code>clog1p</code>, <code>clog2</code>, <code>clgamma</code>, <code>ctgamma</code><span class="t-rev-inl t-since-c23"><span>, <code>csinpi</code>, <code>ccospi</code>, <code>ctanpi</code>, <code>casinpi</code>, <code>cacospi</code>, <code>catanpi</code>, <code>ccompoundn</code>, <code>cpown</code>, <code>cpowr</code>, <code>crootn</code>, <code>crsqrt</code>, <code>cexp10m1</code>, <code>cexp10</code>, <code>cexp2m1</code>, <code>clog10p1</code>, <code>clog2p1</code>, <code>clogp1</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> and their -f and -l suffixed variants, in <a href="../numeric/complex" title="c/numeric/complex"><code><complex.h></code></a></span> <span class="t-mark-rev t-since-c99">(since C99)</span>
</li> <li>beginning with <code>is</code> or <code>to</code> followed by a lowercase letter, in <a href="../string/byte" title="c/string/byte"><code><ctype.h></code></a><span class="t-rev-inl t-since-c95"><span> and <a href="../string/wide" title="c/string/wide"><code><wctype.h></code></a></span><span><span class="t-mark-rev t-since-c95">(since C95)</span></span></span>
</li> <li>beginning with <code>str</code> <span class="t-rev-inl t-since-c23"><span>or <code>wcs</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> followed by a lowercase letter, in <a href="../string/byte" title="c/string/byte"><code><stdlib.h></code></a> <span class="t-rev-inl t-since-c23"><span>and <a href="../types/integer" title="c/types/integer"><code><inttypes.h></code></a></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c23">
<span>beginning with <code>cr_</code>, in <a href="../numeric/math" title="c/numeric/math"><code><math.h></code></a></span> <span class="t-mark-rev t-since-c23">(since C23)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c95">
<span>beginning with <code>wcs</code> followed by a lowercase letter, in <a href="../string/wide" title="c/string/wide"><code><wchar.h></code></a></span> <span class="t-mark-rev t-since-c95">(since C95)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>atomic_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><stdatomic.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>cnd_</code>, <code>mtx_</code>, <code>thrd_</code> or <code>tss_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><threads.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> </ul> </li> <li>
<i>typedef names</i><span class="t-rev-inl t-since-c23"><span>, all of which are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> <ul> <li class="t-rev-inl t-rev-inl-noborder t-since-c99">
<span>beginning with <code>int</code> or <code>uint</code> and ending with <code>_t</code>, in <a href="../types/integer" title="c/types/integer"><code><stdint.h></code></a></span> <span class="t-mark-rev t-since-c99">(since C99)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>atomic_</code> or <code>memory_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><stdatomic.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>cnd_</code>, <code>mtx_</code>, <code>thrd_</code> or <code>tss_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><threads.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> </ul> </li> <li>
<i>macro names</i> <ul> <li>beginning with <code>E</code> followed by a digit or an uppercase letter, in <a href="../error/errno_macros" title="c/error/errno macros"><code><errno.h></code></a>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c99">
<span>beginning with <code>FE_</code> followed by an uppercase letter, in <a href="../numeric/fenv" title="c/numeric/fenv"><code><fenv.h></code></a></span> <span class="t-mark-rev t-since-c99">(since C99)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c23">
<span>beginning with <code>DBL_</code>, <code>DEC32_</code>, <code>DEC64_</code>, <code>DEC128_</code>, <code>DEC_</code>, <code>FLT_</code>, or <code>LDBL_</code> followed by an uppercase letter, in <a href="../types/limits" title="c/types/limits"><code><float.h></code></a>; these identifiers are potentially reserved</span> <span class="t-mark-rev t-since-c23">(since C23)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c99">
<span>beginning with <code>INT</code> or <code>UINT</code> and ending with <code>_MAX</code>, <code>_MIN</code><span class="t-rev-inl t-since-c23"><span>, <code>_WIDTH</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>, or <code>_C</code>, in <a href="../types/integer" title="c/types/integer"><code><stdint.h></code></a><span class="t-rev-inl t-since-c23"><span>; these identifiers are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span></span> <span class="t-mark-rev t-since-c99">(since C99)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c99">
<span>beginning with <code>PRI</code> or <code>SCN</code> followed by lowercase letter or the letter <code>X</code>, in <a href="../types/integer" title="c/types/integer"><code><inttypes.h></code></a><span class="t-rev-inl t-since-c23"><span>; these identifiers are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span></span> <span class="t-mark-rev t-since-c99">(since C99)</span>
</li> <li>beginning with <code>LC_</code> followed by an uppercase letter, in <a href="../locale/lc_categories" title="c/locale/LC categories"><code><locale.h></code></a>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c23">
<span>beginning with <code>FP_</code> followed by an uppercase letter, in <a href="../numeric/math" title="c/numeric/math"><code><math.h></code></a></span> <span class="t-mark-rev t-since-c23">(since C23)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c23">
<span>beginning with <code>MATH_</code> followed by an uppercase letter, in <a href="../numeric/math" title="c/numeric/math"><code><math.h></code></a>; these identifiers are potentially reserved</span> <span class="t-mark-rev t-since-c23">(since C23)</span>
</li> <li>beginning with <code>SIG</code> or <code>SIG_</code> followed by an uppercase letter, in <a href="../program" title="c/program"><code><signal.h></code></a>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>TIME_</code> followed by an uppercase letter, in <a href="../chrono/timespec_get" title="c/chrono/timespec get"><code><time.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>ATOMIC_</code> followed by an uppercase letter, in <a href="../thread" title="c/thread"><code><stdatomic.h></code></a><span class="t-rev-inl t-since-c23"><span>; these identifiers are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> </ul> </li> <li>
<i>enumeration constants</i><span class="t-rev-inl t-since-c23"><span>, all of which are potentially reserved</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> <ul> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>memory_order_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><stdatomic.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> <li class="t-rev-inl t-rev-inl-noborder t-since-c11">
<span>beginning with <code>cnd_</code>, <code>mtx_</code>, <code>thrd_</code> or <code>tss_</code> followed by a lowercase letter, in <a href="../thread" title="c/thread"><code><threads.h></code></a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li> </ul> </li> </ul> <table class="t-rev-begin"> <tr class="t-rev t-since-c23">
<td> <p>Implementations are recommended to warn when on declaration or definition of potentially reserved identifiers, except when</p>
<ul>
<li> the declaration is a non-definition declaration of an identifier with external linkage provided by the implementation, and </li>
<li> the type used in the declaration is <a href="types#Compatible_types" title="c/language/types" class="mw-redirect">compatible</a> with that used in the definition. </li>
</ul> </td> <td><span class="t-mark-rev t-since-c23">(since C23)</span></td>
</tr> </table> <h3 id="Translation_limits"> Translation limits</h3> <p>Even though there is no specific limit on the length of identifiers, early compilers had limits on the number of significant initial characters in identifiers and the linkers imposed stricter limits on the names with <a href="storage_duration" title="c/language/storage duration">external linkage</a>. C requires that at least the following limits are supported by any standard-compliant implementation:</p>
<table class="t-rev-begin"> <tr class="t-rev t-until-c99">
<td> <ul>
<li>31 significant initial characters in an internal identifier or a macro name </li>
<li>6 significant initial characters in an external identifier </li>
<li>511 external identifiers in one translation unit </li>
<li>127 identifiers with block scope declared in one block </li>
<li>1024 macro identifiers simultaneously defined in one preprocessing translation unit </li>
</ul> </td> <td><span class="t-mark-rev t-until-c99">(until C99)</span></td>
</tr> <tr class="t-rev t-since-c99">
<td> <ul>
<li>63 significant initial characters in an internal identifier or a macro name </li>
<li>31 significant initial characters in an external identifier </li>
<li>4095 external identifiers in one translation unit </li>
<li>511 identifiers with block scope declared in one block </li>
<li>4095 macro identifiers simultaneously defined in one preprocessing translation unit </li>
</ul> </td> <td><span class="t-mark-rev t-since-c99">(since C99)</span></td>
</tr> </table> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul>
<li> 5.2.4.1 Translation limits (p: 19-20) </li>
<li> 6.4.2 Identifiers (p: 43) </li>
<li> 6.10.8 Predefined macro names (p: 127-129) </li>
<li> 6.11.9 Predefined macro names (p: 130) </li>
<li> 7.31 Future library directions (p: 332-333) </li>
<li> K.3.1.2 Reserved identifiers (p: 425) </li>
</ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul>
<li> 5.2.4.1 Translation limits (p: 25-26) </li>
<li> 6.4.2 Identifiers (p: 59-60) </li>
<li> 6.10.8 Predefined macro names (p: 175-176) </li>
<li> 6.11.9 Predefined macro names (p: 179) </li>
<li> 7.31 Future library directions (p: 455-457) </li>
<li> K.3.1.2 Reserved identifiers (p: 584) </li>
</ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul>
<li> 5.2.4.1 Translation limits (p: 20-21) </li>
<li> 6.4.2 Identifiers (p: 51-52) </li>
<li> 6.10.8 Predefined macro names (p: 160-161) </li>
<li> 6.11.9 Predefined macro names (p: 163) </li>
<li> 7.26 Future library directions (p: 401-402) </li>
</ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul>
<li> 2.2.4.1 Translation limits </li>
<li> 3.1.2 Identifiers </li>
<li> 3.8.8 Predefined macro names </li>
</ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/identifiers" title="cpp/language/identifiers">C++ documentation</a></span> for <span class=""><span>Identifiers</span></span> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/language/identifier" class="_attribution-link">https://en.cppreference.com/w/c/language/identifier</a>
</p>
</div>
|