Identifiers

From RAD Studio
Jump to: navigation, search

Go Up to Tokens Overview Index

Here is the formal definition of an identifier:

identifier:

  • identifier-nondigit
  • identifier identifier-nondigit
  • identifier digit

identifier identifier-nondigit:

  • nondigit
  • universal-character-name (Unicode)
  • other implementation-defined characters


nondigit: one of

  • a b c d e f g h i j k l m n o p q r s t u v w x y z _
  • A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

digit: one of

  • 0 1 2 3 4 5 6 7 8 9

Naming and length restrictions

Identifiers are arbitrary names of any length given to classes, objects, functions, variables, user-defined data types, and so on. Identifiers can contain any characters (including ASCII and Unicode), the underscore character "_", and the digits 0 to 9. All characters in an identifier are significant.

  • The first character of an identifier must be a letter or an underscore.
  • By default, the compiler recognizes all characters as significant. The number of significant characters can be reduced by menu and command-line options, but not increased. To change the significant character length, set the length you want in Project > Options > C++ Compiler > Advanced > Identifier Length.

Unicode characters in an identifier universal-character-name, must have an encoding in ISO 10646 that falls into one of the ranges specified in Annex A of TR 10176:2003. Ranges are specified for Latin, Greek, Cyrillic, Armenian, Hebrew, Arabic, Syriac, Thaana, Devanagari, Bengali, anGurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar, Georgian, Ethiopic, Cherokee, Canadian Aboriginal syllabics, Ogham, Runic, Khmer, Mongolian, Hiragana, Katakana, Bopomofo, CJK Unified Ideographs, Yi, Hangul, digits, and special characters.

Case sensitivity

Identifiers in C and C++ are case sensitive, so that Sum, sum and suM are distinct identifiers.

Global identifiers imported from other modules follow the same naming and significance rules as normal identifiers. However, you have the option of suspending case sensitivity to allow compatibility when linking with case-insensitive languages. With the case-insensitive option, the globals Sum and sum are considered identical, resulting in a possible. "Duplicate symbol" warning during linking.

An exception to these rules is that identifiers of type __pascal are always converted to all uppercase for linking purposes.

Uniqueness and scope

Although identifier names are arbitrary (within the rules stated), errors result if the same name is used for more than one identifier within the same scope and sharing the same name space. Duplicate names are legal for different name spaces regardless of scope rules.

See Also