C
Christopher Key
Hello,
I'm struggling to understand the exact requirement for the INTn_C /
UINTn_C macros, beyond being a tidier alternative to putting a cast on
the front.
Reading through n1124, it seems that any integer literals without
suffixes will have a type sufficently large to hold them (with the
exception of base 10 literals never having unsigned type, but this only
need a U suffix to overcome).
Is there therefore any significant difference between the following on a
standard 32bit int platform?
(INT64_C(1000000000)) /* 10^9 */
and
((int64_t) 1000000000) /* 10^9 */
or
(INT64_C(10000000000)) /* 10^10 */
and
(10000000000) /* 10^10 */
I'm wondering if this is something left over from previous C standards.
If I set my compiler to C89 rather than C99, it starts spitting out
warnings about values being too large for long. Were the rules for
integer literals different, or did they just stop at long?
If this is the case, is it therefore necessary to wrap values larger
that 2^32-1 (2^31-1 for base 10 literals) in INTn_C macros to ensure the
code compiles correctly on a C89 compiler?
I'm struggling to understand the exact requirement for the INTn_C /
UINTn_C macros, beyond being a tidier alternative to putting a cast on
the front.
Reading through n1124, it seems that any integer literals without
suffixes will have a type sufficently large to hold them (with the
exception of base 10 literals never having unsigned type, but this only
need a U suffix to overcome).
Is there therefore any significant difference between the following on a
standard 32bit int platform?
(INT64_C(1000000000)) /* 10^9 */
and
((int64_t) 1000000000) /* 10^9 */
or
(INT64_C(10000000000)) /* 10^10 */
and
(10000000000) /* 10^10 */
I'm wondering if this is something left over from previous C standards.
If I set my compiler to C89 rather than C99, it starts spitting out
warnings about values being too large for long. Were the rules for
integer literals different, or did they just stop at long?
If this is the case, is it therefore necessary to wrap values larger
that 2^32-1 (2^31-1 for base 10 literals) in INTn_C macros to ensure the
code compiles correctly on a C89 compiler?