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 prior to version 10) | (since C99) |
Identifiers can denote the following types of entities:
Every identifier other than macro names or macro parameter names 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):
All other identifiers are available. Identifiers that are not reserved or potentially reserved (since C23) can be used 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.
The standard library reserves every identifiers it provides. Reserved identifiers that have external linkage (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.
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. Implementations are only allowed to provide external definitions of potentially reserved identifiers that are reserved as function names. 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. | (since C23) |
Following identifiers are reserved or potentially reserved (since C23) for the implementation or future use by the standard library.
cerf
, cerfc
, cexp2
, cexpm1
, clog10
, clog1p
, clog2
, clgamma
, ctgamma
, csinpi
, ccospi
, ctanpi
, casinpi
, cacospi
, catanpi
, ccompoundn
, cpown
, cpowr
, crootn
, crsqrt
, cexp10m1
, cexp10
, cexp2m1
, clog10p1
, clog2p1
, clogp1
(since C23) and their -f and -l suffixed variants, in <complex.h>
(since C99)
is
or to
followed by a lowercase letter, in <ctype.h>
and <wctype.h>
(since C95)
str
or wcs
(since C23) followed by a lowercase letter, in <stdlib.h>
and <inttypes.h>
(since C23)
cr_
, in <math.h>
(since C23)
wcs
followed by a lowercase letter, in <wchar.h>
(since C95)
atomic_
followed by a lowercase letter, in <stdatomic.h>
(since C11)
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
(since C11)
int
or uint
and ending with _t
, in <stdint.h>
(since C99)
atomic_
or memory_
followed by a lowercase letter, in <stdatomic.h>
(since C11)
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
(since C11)
E
followed by a digit or an uppercase letter, in <errno.h>
FE_
followed by an uppercase letter, in <fenv.h>
(since C99)
DBL_
, DEC32_
, DEC64_
, DEC128_
, DEC_
, FLT_
, or LDBL_
followed by an uppercase letter, in <float.h>
; these identifiers are potentially reserved (since C23)
INT
or UINT
and ending with _MAX
, _MIN
, _WIDTH
(since C23), or _C
, in <stdint.h>
; these identifiers are potentially reserved (since C23) (since C99)
PRI
or SCN
followed by lowercase letter or the letter X
, in <inttypes.h>
; these identifiers are potentially reserved (since C23) (since C99)
LC_
followed by an uppercase letter, in <locale.h>
FP_
followed by an uppercase letter, in <math.h>
(since C23)
MATH_
followed by an uppercase letter, in <math.h>
; these identifiers are potentially reserved (since C23)
SIG
or SIG_
followed by an uppercase letter, in <signal.h>
TIME_
followed by an uppercase letter, in <time.h>
(since C11)
ATOMIC_
followed by an uppercase letter, in <stdatomic.h>
; these identifiers are potentially reserved (since C23) (since C11)
memory_order_
followed by a lowercase letter, in <stdatomic.h>
(since C11)
cnd_
, mtx_
, thrd_
or tss_
followed by a lowercase letter, in <threads.h>
(since C11)
Implementations are recommended to warn when on declaration or definition of potentially reserved identifiers, except when.
| (since C23) |
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.
https://en.cppreference.com/w/c/language/identifier