定数
定数の概要:インデックス への移動
定数またはリテラルとは、一定の数や文字の値を表すトークンです。用語「定数」や「リテラル」は、ここでは混在して使用されます。
コンパイラは、次の定数のクラスをサポートしています:整数、浮動小数点、文字および文字列、ブーリアン、列挙型。
数値型の内部表現は、これらの型が、プロセッサ アーキテクチャにおいてどのように内部的に表現されるかを表しています。
定数のデータ型は、そのようなヒントをソース コード内で使用される数値および書式として使用して、コンパイラよって推測されます。定数の書式定義は、次の表の通りです:
定数: 書式定義:
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 |