Integer constants can be decimal (base 10), octal (base 8) or hexadecimal (base 16). In the absence of any overriding suffixes, the data type of an integer constant is derived from its value, as shown in Integer constants without L or U.. Note that the rules vary between decimal and nondecimal constants.
Decimal
Decimal constants from 0 to 4,294,967,295 are allowed. Constants exceeding this limit are truncated. Decimal constants must not use an initial zero. An integer constant that has an initial zero is interpreted as an octal constant. Thus,
int i = 10; /*decimal 10 */ int i = 010; /*decimal 8 */ int i = 0; /*decimal 0 = octal 0 */
Octal
All constants with an initial zero are taken to be octal. If an octal constant contains the illegal digits 8 or 9, an error is reported. Octal constants exceeding 037777777777 are truncated.
Hexadecimal
All constants starting with 0x (or 0X) are taken to be hexadecimal. Hexadecimal constants exceeding 0xFFFFFFFF are truncated.
long and unsigned suffixes
The suffix L (or l) attached to any constant forces the constant to be represented as a long. Similarly, the suffix U (or u) forces the constant to be unsigned. It is unsigned long if the value of the number itself is greater than decimal 65,535, regardless of which base is used. You can use both L and U suffixes on the same constant in any order or case: ul, lu, UL, and so on.
The data type of a constant in the absence of any suffix (U, u, L, or l) is the first of the following types that can accommodate its value:
Decimal |
int, long int, unsigned long int |
Octal |
int, unsigned int, long int, unsigned long int |
Hexadecimal |
int, unsigned int, long int, unsigned long int |
If the constant has a U or u suffix, its data type will be the first of unsigned int, unsigned long int that can accommodate its value.
If the constant has an L or l suffix, its data type will be the first of long int, unsigned long int that can accommodate its value.
If the constant has both u and l suffixes, (ul, lu, Ul, lU, uL, Lu, LU or UL), its data type will be unsigned long int.
Integer constants without L or U summarizes the representations of integer constants in all three bases. The data types indicated assume no overriding L or U suffix has been used.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|