Constants

From RAD Studio
Jump to: navigation, search

Go Up to Constants Overview Index

Constants or literals are tokens representing fixed numeric or character values. The terms "constant" and "literal" are used interchangeably here.

The compiler supports the following classes of constants: integer, floating point, character and string, boolean, and enumeration.

Internal representation of numerical types shows how these types are represented internally in a processor architecture.

The data type of a constant is deduced by the compiler using such clues as numeric value and the format used in the source code. The formal definition of a constant is shown in the following table.

Constants: Formal Definitions:

constant:
  floating-constant
  integer-constant
  character-constant
  string-literal
  enumeration-constant
  boolean-literal 
enumeration-constant:
  identifier
 floating-constant:
  fractional-constant <exponent-part> <floating-suffix>
  digit-sequence exponent-part <floating-suffix>
 character-constant:
   'c-char-sequence'     (char - ANSI)
   L'c-char-sequence'    (wchar_t - Widestring)
   u'c-char-sequence'    (char16_t - UTF-16) (С++0x)
   U'c-char-sequence'    (char32_t - UTF-32) (С++0x)
fractional-constant:
  <digit-sequence>  . digit-sequence
  digit-sequence  . 
c-char-sequence:
  c-char
  c-char-sequence c-char
exponent-part:
  e <sign> digit-sequence
  E <sign> digit-sequence
c-char:
  Any character in the source character set except
    the single-quote ( ' ), 
    backslash ( \ ),
    or newline character 
  escape-sequence
sign: one of
  + -
escape-sequence:  
  simple-escape-sequence
  octal-escape-sequence
  hexadecimal-escape-sequence
digit-sequence:
  digit
  digit-sequence digit
simple-escape-sequence: one of 
  \" \' \? \\
  \a \b \f \n \r \t \v
floating-suffix: one of
  f l F L
octal-escape-sequence:
  \ octal-digit   (\o)
  \ octal-digit octal-digit   (\oo)
  \ octal-digit octal-digit octal-digit   (\ooo)
 integer-constant:
  decimal-constant <integer-suffix>
  octal-constant <integer-suffix>
  hexadecimal-constant <integer-suffix>
hexadecimal-escape-sequence:
  \x hexadecimal-digit   (\xh)
  \X hexadecimal-digit   (\Xh)
  hexadecimal-escape-sequence hexadecimal-digit
decimal-constant:
  nonzero-digit
  decimal-constant digit
 string-literal:
   "s-char-sequence"     (char* - ANSI)
   L"s-char-sequence"    (wchar_t* - Widestring)
   u"s-char-sequence"    (char16_t* - UTF-16) (С++0x)
   U"s-char-sequence"    (char32_t* - UTF-32) (С++0x)
octal-constant:
  0
  octal-constant octal-digit
s-char-sequence:
  s-char
  s-char-sequence s-char
hexadecimal-constant:
  0x hexadecimal-digit
  0X hexadecimal-digit
  hexadecimal-constant hexadecimal-digit
s-char:
  Any character in the source character set except
    the double-quote ( " ), 
    backslash ( \ ),
    or newline character 
  escape-sequence
nonzero-digit: one of
  1 2 3 4 5 6 7 8 9
 boolean-literal:
  true
  false
octal-digit: one of
  0 1 2 3 4 5 6 7
hexadecimal-digit: one of
  0 1 2 3 4 5 6 7 8 9
  a b c d e f
  A B C D E F
integer-suffix:
  unsigned-suffix <long-suffix>
  long-suffix <unsigned-suffix>
  <unsigned-suffix> size-suffix 
unsigned-suffix: one of
  u U
long-suffix: one of
  l L 
 size-suffix: one of
  i8 I8 i16 I16  i32 I32 i64 I64 

See Also