可能有些文字对于 LL 后缀来说太大了
是的,如果整数常量超出(u)intmax_t的范围,就太大了,不管有没有LL。
请参阅Assigning 128 bit integer in C
了解类似问题。
LL 和 LLU 不适用于类型。它们用于整数常量。
L 或 LL 确保常量的最小 类型。 intmax_t 没有后缀。
123 is an `int`
123L is a `long`
123LL is a `long long`
123456789012345 is a `long long` on OP's hypothetical system even without LL
intmax_t 可能与long long 具有相同的范围 - 或者可能更宽。 intmax_t 和 long long 都至少是 64 位的。
对于启用了良好警告的编译器,如果常量超出intmax_t 范围,则会出现警告。例子:
// warning: integer overflow in expression
intmax_t yuuge1 = (intmax_t)123456*1000000000000000000 + 789101112131411516;
// warning: overflow in implicit constant conversion [-Woverflow]
intmax_t yuuge2 = 123456789101112131411516;
C 为最大宽度整数常量提供宏
以下宏扩展为一个整数常量表达式,其值由其参数指定,类型为 intmax_t:C11 §7.20.4.2 1
INTMAX_C(value)
INTMAX_C(value) 确实有限制
这些宏的任何实例中的参数都应该是一个无后缀的整数常量......其值不超过相应类型的限制。
以下内容在具有 64 位 intmax_t 的机器上不满足该要求。
// Not so portable code
intmax_t yuuge = INTMAX_C(123456789101112131411516);
#预处理也仅限于intmax_t。
尝试在(u)int64_t 范围之外创建常量的代码很容易出现可移植性问题。为了可移植性,建议使用另一种编码方法(避免使用如此大的常量)。