Note: IBM supports selected
features of C++11, known as C++0x before its ratification. IBM will
continue to develop and implement the features of this standard. The
implementation of the language level is based on IBM's interpretation
of the standard. Until IBM's implementation of all the C++11 features
is complete, including the support of a new C++11 standard library,
the implementation may change from release to release. IBM makes no
attempt to maintain compatibility, in source, binary, or listings
and other compiler interfaces, with earlier releases of IBM's implementation
of the new C++11 features.
Integer
literals are numbers that do not have a decimal point or an exponential
part. They can be represented as:
An integer literal might have a
prefix that specifies its base, or a suffix that specifies its type.

Integer literal syntax
>>-+-decimal_constant-----+--+---------------+-----------------><
+-octal_constant-------+ +-+-l--+--+---+-+
'-hexadecimal_constant-' | +-L--+ +-u-+ |
| +-ll-+ '-U-' |
| '-LL-' |
'-+-u-+--+----+-'
'-U-' +-l--+
+-L--+
+-ll-+
'-LL-'
The long long features
There
are two
long long features:
- the C99 long long feature
- the non-C99 long long feature
Note: The syntax of integer literals is the same for
both of the long long features.

Both of the two features have the corresponding extension
parts:
- the C99 long long feature with the associated IBM extensions
- the non-C99 IBM long
long extension

Types of integer literals
outside of C99 and C++11
The following
table lists the integer literals and shows the possible data types
when the C99
long long feature is not enabled.
Table 1. Types of integer literals outside of C99 and
C++111Representation |
Suffix |
Possible data types |
|
|
int |
unsigned int |
long int |
unsigned long int |
long long int |
unsigned long long int |
Decimal |
None |
+ |
|
+ |
+2 |
|
|
Octal, Hex |
None |
+ |
+ |
+ |
+ |
|
|
All |
u or U |
|
+ |
|
+ |
|
|
Decimal |
l or L |
|
|
+ |
+ |
|
|
Octal, Hex |
l or L |
|
|
+ |
+ |
|
|
All |
Both u or U and l or L |
|
|
|
+ |
|
|
Decimal |
ll or LL |
|
|
|
|
+ |
+ |
Octal, Hex |
ll or LL |
|
|
|
|
+ |
+ |
All |
Both u or U and ll or LL |
|
|
|
|
|
+ |
Notes: - When none of the long long features
are enabled, types of integer literals include all the types in this
table except the last two columns.
The unsigned
long int type is not required here in the C++98 and C++03
standards. The C++ compiler includes the type in the implementation
for compatibility purposes only.
|
Types of integer literals in C99 and C++11
When both the C99 and non-C99
long long features
are disabled, integer literals that have one of the following suffixes
cause a severe compile-time error:
- ll or LL
- Both u or U and ll or LL

A decimal literal without a
u or
U in
the suffix is represented by the
unsigned long long int type
if both of the following conditions are satisfied. In this case, the
compiler generates a message to indicate that the value of the literal
is too large for any signed integer type.
- The value of the literal can fit into the unsigned long
long int type.
- The value cannot fit into any of the possible data types that
are indicated in the following table.


To strictly conform to the C++11 standard, the compiler introduces
the extended integer safe behavior to ensure that a signed value never
becomes an unsigned value after a promotion. After you enable this
behavior, if a decimal integer literal that does not have a suffix
containing u or U cannot be represented
by the long long int type, the compiler issues an
error message to indicate that the value of the literal is out of
range. The extended integer safe behavior is the only difference between
the C99 long long feature with the associated IBM extensions
and the C99 long long feature.

The
following table lists the integer literals and shows the possible
data types when the C99
long long feature is enabled.
Table 2. Types of integer literals in C99 and C++11Representation |
Suffix |
Possible data types |
|
|
int |
unsigned int |
long int |
unsigned long int |
long long int |
unsigned long long int |
Decimal |
None |
+ |
|
+ |
|
|
|
Octal, Hex |
None |
+ |
+ |
+ |
+ |
|
|
All |
u or U |
|
+ |
|
+ |
|
|
Decimal |
l or L |
|
|
+ |
|
|
|
Octal, Hex |
l or L |
|
|
+ |
+ |
|
|
All |
Both u or U and l or L |
|
|
|
+ |
|
|
Decimal |
ll or LL |
|
|
|
|
+ |
+1 |
Octal, Hex |
ll or LL |
|
|
|
|
+ |
+ |
All |
Both u or U and ll or LL |
|
|
|
|
|
+ |
Note:  The compiler does not support this type if the extended
integer safe behavior is enabled.
In 32-bit mode, an unsuffixed decimal constant
of type signed long long is given the type signed
long in 64-bit mode when the constant is less than ULLONG_MAX.
|
Decimal integer
literals
A decimal integer literal contains any of
the digits 0 through 9. The first digit cannot be 0. Integer literals
beginning with the digit 0 are interpreted as an octal integer literal
rather than as a decimal integer literal.

Decimal integer literal syntax
.--------------.
V |
>>-digit_1_to_9----digit_0_to_9-+------------------------------><
See the following examples
of decimal literals:
485976
5
A plus (+) or minus (-) symbol can precede a decimal
integer literal. The operator is treated as a unary operator rather
than as part of the literal. Consider the following example:
-433132211
+20
Hexadecimal
integer literals
A hexadecimal integer literal begins
with the 0 digit followed by either an x or X, followed by any combination
of the digits 0 through 9 and the letters a through f or A through
F. The letters A (or a) through F (or f) represent the values 10
through 15, respectively.

Hexadecimal integer literal syntax
.------------------.
V |
>>-+-0x-+----+-digit_0_to_f-+-+--------------------------------><
'-0X-' '-digit_0_to_F-'
See the following examples
of hexadecimal integer literals:
0x3b24
0XF96
0x21
0x3AA
0X29b
0X4bD
Octal integer
literals
An octal integer literal begins with the
digit 0 and contains any of the digits 0 through 7.

Octal integer literal syntax
.--------------.
V |
>>-0----digit_0_to_7-+-----------------------------------------><
See the following examples
of octal integer literals:
0
0125
034673
03245