Skip to main content
Update with information from recent standards up to C++23
Source Link

The rules (which did not changeare still unchanged in C++11C++23):

  • Reserved in any scope, including for use as implementation macros:
    • identifiers beginning with an underscore followed immediately by an uppercase letter
    • identifiers containing adjacent underscores (or "double underscore")
  • Reserved in the global namespace:
    • identifiers beginning with an underscore
  • Also, everything in the std namespace is reserved. (You are allowed to add template specializations, though.)
  • User-defined literal suffix identifiers must start with an underscore (since C++11) and must not contain double underscore (reserved since C++23)

From the 2003 C++ Standard (appears in section 5.10.3 Identifiers [lex.name] since C++17):

17.4.3.1.2 Global names [lib.global.names]

Certain sets of names and function signatures are always reserved to the implementation:

  • Each name that contains a double underscore (__) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
  • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.165

165) Such names are also reserved in namespace ::std (17.4.3.1).

From the 2023 C++ Standard:

16.4.5.3.6 User-defined literal suffixes [usrlit.suffix]

Literal suffix identifiers ([over.literal]) that do not start with an underscore are reserved for future standardization.

Literal suffix identifiers that contain a double underscore __ are reserved for use by C++ implementations.

The rules (which did not change in C++11):

  • Reserved in any scope, including for use as implementation macros:
    • identifiers beginning with an underscore followed immediately by an uppercase letter
    • identifiers containing adjacent underscores (or "double underscore")
  • Reserved in the global namespace:
    • identifiers beginning with an underscore
  • Also, everything in the std namespace is reserved. (You are allowed to add template specializations, though.)

From the 2003 C++ Standard:

17.4.3.1.2 Global names [lib.global.names]

Certain sets of names and function signatures are always reserved to the implementation:

  • Each name that contains a double underscore (__) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
  • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.165

165) Such names are also reserved in namespace ::std (17.4.3.1).

The rules (which are still unchanged in C++23):

  • Reserved in any scope, including for use as implementation macros:
    • identifiers beginning with an underscore followed immediately by an uppercase letter
    • identifiers containing adjacent underscores (or "double underscore")
  • Reserved in the global namespace:
    • identifiers beginning with an underscore
  • Also, everything in the std namespace is reserved. (You are allowed to add template specializations, though.)
  • User-defined literal suffix identifiers must start with an underscore (since C++11) and must not contain double underscore (reserved since C++23)

From the 2003 C++ Standard (appears in section 5.10.3 Identifiers [lex.name] since C++17):

17.4.3.1.2 Global names [lib.global.names]

Certain sets of names and function signatures are always reserved to the implementation:

  • Each name that contains a double underscore (__) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
  • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.165

165) Such names are also reserved in namespace ::std (17.4.3.1).

From the 2023 C++ Standard:

16.4.5.3.6 User-defined literal suffixes [usrlit.suffix]

Literal suffix identifiers ([over.literal]) that do not start with an underscore are reserved for future standardization.

Literal suffix identifiers that contain a double underscore __ are reserved for use by C++ implementations.

Add extra single-space so list indenting works as appears to be intended. Add missing terminating colons `:` for consistency.
Source Link
rand'Chris
  • 1.3k
  • 13
  • 31
  • Names beginning with a capital E followed a digit or uppercase letter:
  • may be used for additional error code names.
    • may be used for additional error code names.
  • Names that begin with either is or to followed by a lowercase letter
  • may be used for additional character testing and conversion functions.:
    • may be used for additional character testing and conversion functions.
  • Names that begin with LC_ followed by an uppercase letter
  • may be used for additional macros specifying locale attributes.:
    • may be used for additional macros specifying locale attributes.
  • Names of all existing mathematics functions suffixed with f or l are reserved
  • for corresponding functions that operate on float and long double arguments, respectively.:
    • for corresponding functions that operate on float and long double arguments, respectively.
  • Names that begin with SIG followed by an uppercase letter are reserved
  • for additional signal names.:
    • for additional signal names.
  • Names that begin with SIG_ followed by an uppercase letter are reserved
  • for additional signal actions.:
    • for additional signal actions.
  • Names beginning with str, mem, or wcs followed by a lowercase letter are reserved
  • for additional string and array functions.:
    • for additional string and array functions.
  • Names beginning with PRI or SCN followed by any lowercase letter or X are reserved
  • for additional format specifier macros:
    • for additional format specifier macros
  • Names that end with _t are reserved
  • for additional type names.:
    • for additional type names.
  • Names beginning with a capital E followed a digit or uppercase letter:
  • may be used for additional error code names.
  • Names that begin with either is or to followed by a lowercase letter
  • may be used for additional character testing and conversion functions.
  • Names that begin with LC_ followed by an uppercase letter
  • may be used for additional macros specifying locale attributes.
  • Names of all existing mathematics functions suffixed with f or l are reserved
  • for corresponding functions that operate on float and long double arguments, respectively.
  • Names that begin with SIG followed by an uppercase letter are reserved
  • for additional signal names.
  • Names that begin with SIG_ followed by an uppercase letter are reserved
  • for additional signal actions.
  • Names beginning with str, mem, or wcs followed by a lowercase letter are reserved
  • for additional string and array functions.
  • Names beginning with PRI or SCN followed by any lowercase letter or X are reserved
  • for additional format specifier macros
  • Names that end with _t are reserved
  • for additional type names.
  • Names beginning with a capital E followed a digit or uppercase letter:
    • may be used for additional error code names.
  • Names that begin with either is or to followed by a lowercase letter:
    • may be used for additional character testing and conversion functions.
  • Names that begin with LC_ followed by an uppercase letter:
    • may be used for additional macros specifying locale attributes.
  • Names of all existing mathematics functions suffixed with f or l are reserved:
    • for corresponding functions that operate on float and long double arguments, respectively.
  • Names that begin with SIG followed by an uppercase letter are reserved:
    • for additional signal names.
  • Names that begin with SIG_ followed by an uppercase letter are reserved:
    • for additional signal actions.
  • Names beginning with str, mem, or wcs followed by a lowercase letter are reserved:
    • for additional string and array functions.
  • Names beginning with PRI or SCN followed by any lowercase letter or X are reserved:
    • for additional format specifier macros
  • Names that end with _t are reserved:
    • for additional type names.
correct misinformation about C++ "importing" the C standard
Source Link
Jan Schultke
  • 43.6k
  • 8
  • 109
  • 188

BecauseThe C++ language is based on the C standardlanguage (1.1/2, C++03), and C99 is a normative reference (1.2/1, C++03) these also apply, so it's useful to know the restrictions from the 1999 C Standard (although they do not apply to C++ directly):

Because C++ is based on the C standard (1.1/2, C++03) and C99 is a normative reference (1.2/1, C++03) these also apply, from the 1999 C Standard:

The C++ language is based on the C language (1.1/2, C++03), and C99 is a normative reference (1.2/1, C++03), so it's useful to know the restrictions from the 1999 C Standard (although they do not apply to C++ directly):

explained w/ link what an "implementation" is.
Source Link
Loading
Markdown the identifier fragments
Source Link
Toby Speight
  • 32.1k
  • 58
  • 82
  • 117
Loading
Corrected the section number being quoted from.
Source Link
Donal Lafferty
  • 6k
  • 7
  • 47
  • 61
Loading
deleted 1 character in body
Source Link
Deduplicator
  • 46k
  • 7
  • 73
  • 125
Loading
the previous edit actually made it even more ambiguous
Source Link
Ben Voigt
  • 285.9k
  • 45
  • 444
  • 764
Loading
remove ambiguous wording
Source Link
flogram_dev
  • 43k
  • 11
  • 109
  • 161
Loading
deleted 29 characters in body
Source Link
R. Martinho Fernandes
  • 236k
  • 73
  • 443
  • 518
Loading
added 32 characters in body
Source Link
Nicol Bolas
  • 481.2k
  • 66
  • 861
  • 1.1k
Loading
added 135 characters in body
Source Link
R. Martinho Fernandes
  • 236k
  • 73
  • 443
  • 518
Loading
anything is reserved in the std namespace, not only identifiers beginning with an underscore
Source Link
sbi
  • 225k
  • 46
  • 267
  • 447
Loading
Fixed quotes
Source Link
Mike DeSimone
  • 43k
  • 10
  • 79
  • 97
Loading
clarify; shift emphasis on names which may be macros to where it belongs
Source Link
Roger Pate
Roger Pate
Loading
clean up; clarify; make this a more useful CW to reference; added 2 characters in body
Source Link
Roger Pate
Roger Pate
Loading
Rework the POSIX x-refs.
Source Link
Jonathan Leffler
  • 759.3k
  • 145
  • 961
  • 1.3k
Loading
Add quote from C99; clarify a couple of earlier paragraphs.
Source Link
Jonathan Leffler
  • 759.3k
  • 145
  • 961
  • 1.3k
Loading
Add POSIX 2008 reference and the 'nuanced' comment.
Source Link
Jonathan Leffler
  • 759.3k
  • 145
  • 961
  • 1.3k
Loading
added 216 characters in body
Source Link
Loki Astari
  • 266.5k
  • 87
  • 344
  • 575
Loading
added 244 characters in body
Source Link
Loki Astari
  • 266.5k
  • 87
  • 344
  • 575
Loading
Post Made Community Wiki by CommunityBot
added 1976 characters in body
Source Link
Loki Astari
  • 266.5k
  • 87
  • 344
  • 575
Loading
added 170 characters in body
Source Link
Loki Astari
  • 266.5k
  • 87
  • 344
  • 575
Loading
added 34 characters in body
Source Link
Loki Astari
  • 266.5k
  • 87
  • 344
  • 575
Loading