这些是 C 和 C++ 中的常量。后缀LL 表示常量是long long 类型,UL 表示unsigned long。
通常,每个L 或l 代表一个long,每个U 或u 代表一个unsigned。所以,例如
1uLL
表示常量1,类型为unsigned long long。
这也适用于浮点数:
1.0f // of type 'float'
1.0 // of type 'double'
1.0L // of type 'long double'
还有字符串和字符,但它们是前缀:
'A' // of type 'char'
L'A' // of type 'wchar_t'
u'A' // of type 'char16_t' (C++0x only)
U'A' // of type 'char32_t' (C++0x only)
在 C 和 C++ 中,整数常量使用它们的原始类型求值,这可能会由于整数溢出而导致错误:
long long nanosec_wrong = 1000000000 * 600;
// ^ you'll get '-1295421440' since the constants are of type 'int'
// which is usually only 32-bit long, not big enough to hold the result.
long long nanosec_correct = 1000000000LL * 600;
// ^ you'll correctly get '600000000000' with this
int secs = 600;
long long nanosec_2 = 1000000000LL * secs;
// ^ use the '1000000000LL' to ensure the multiplication is done as 'long long's.
在 Google Go 中,所有整数都被计算为大整数(不会发生截断),
var nanosec_correct int64 = 1000000000 * 600
并且没有“usual arithmetic promotion”
var b int32 = 600
var a int64 = 1000000000 * b
// ^ cannot use 1000000000 * b (type int32) as type int64 in assignment
所以后缀不是必需的。