K
Keith Thompson
[...]Old Wolf said:Integer constants do not overflow or cause un/impl. defined behaviour.
(Except, of course, for the fact that it is implementation-defined
whether this value exceeds INT_MAX or not).
I don't think that's quite true. Consider an integer const whose
value cannot be represented in any integer type.
For example, assume that long long is 64 bits and there are no extended
integer types. Then the integer constant 99999999999999999999 (that's
20 9's; the value exceeds 2**66) *sort of* violates the constraint
in C99 6.4.4p1:
The value of a constant shall be in the range of representable
values for its type.
except that the C99 6.4.4.1 doesn't say what its type is:
The type of an integer constant is the first of the corresponding
list in which its value can be represented.
[...]
[No suffix, decimal constant]
int
long int
long long int
[...]
If an integer constant cannot be represented by any type in its
list, it may have an extended integer type, if the extended
integer type can represent its value. If all of the types in the
list for the constant are signed, the extended integer type shall
be signed. If all of the types in the list for the constant are
unsigned, the extended integer type shall be unsigned. If the list
contains both signed and unsigned types, the extended integer type
may be signed or unsigned.
If there are no extended integer types, that last paragraph doesn't
apply.
It *should* be a constraint violation, but it may be just undefined
behavior.