An identifier is an arbitrarily long sequence of digits, underscores, lowercase and uppercase Latin letters, and Unicode characters specified using \u
and \U
escape notation (since C99). A valid identifier must begin with a non-digit character (Latin letter, underscore, or Unicode non-digit character (since C99)). Identifiers are case-sensitive (lowercase and uppercase letters are distinct).
It is implementation-defined if raw (not escaped) Unicode characters are allowed in identifiers: char *\U0001f431 = "cat"; // supported char *🐱 = "cat"; // implementation-defined (e.g. works with Clang, but not GCC) | (since C99) |
Identifiers can denote the following types of entities:
Every identifier other than macro name or macro parameter name has scope, belongs to a name space, and may have linkage. 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.
The following identifiers are reserved and may not be declared in a program (doing so invokes undefined behavior):
cerf
, cerfc
, cexp2
, cexpm1
, clog10
, clog1p
, clog2
, clgamma
, ctgamma
and their -f and -l suffixed variants, in <complex.h>
is
or to
followed by a lowercase letter, in <ctype.h>
and wctype.h
str
followed by a lowercase letter, in <stdlib.h>
str
, mem
or wcs
followed by a lowercase letter, in <string.h>
wcs
followed by a lowercase letter, in <wchar.h>
atomic_
followed by a lowercase letter, in <stdatomic.h>
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
int
or uint
and ending with _t
, in <stdint.h>
atomic_
or memory_
followed by a lowercase letter, in <stdatomic.h>
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
E
followed by a digit or an uppercase letter, in <errno.h>
FE_
followed by an uppercase letter, in <fenv.h>
INT
or UINT
and ending with _MAX
, _MIN
, or _C
, in <stdint.h>
PRI
or SCN
followed by lowercase letter or the letter X
, in <stdint.h>
LC_
followed by an uppercase letter, in <locale.h>
SIG
or SIG_
followed by an uppercase letter, in <signal.h>
TIME_
followed by an uppercase letter, in <time.h> ATOMIC_
followed by an uppercase letter, in <stdatomic.h>
memory_order_
followed by a lowercase letter, in <stdatomic.h>
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
All other identifiers are available, with no fear of unexpected collisions when moving programs from one compiler and library to another.
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.
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 external linkage. C requires that at least the following limits are supported by any standard-compliant implementation:
| (until C99) |
| (since C99) |
C++ documentation for Identifiers |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/language/identifier