更新时间:2022-03-15 15:34:14
这些都是在C和C ++的常量。后缀 LL
表示常量的类型为长长
和 UL
办法无符号长
。
These are constants in C and C++. The suffix LL
means the constant is of type long long
, and UL
means unsigned long
.
在一般情况下,每个→
或→
重新presents一个长
,每个 U
或 U
重新presents一个符号
。因此,例如
In general, each L
or l
represents a long
and each U
or u
represents an unsigned
. So, e.g.
1uLL
表示常数1型无符号长长
。
此也适用于浮点数
1.0f // of type 'float'
1.0 // of type 'double'
1.0L // of type 'long double'
和字符串和字符,但它们是prefixes:
and strings and characters, but they are prefixes:
'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 ++中的整型常量使用它们的原始类型,它可能会由于整数溢出漏洞评估:
In C and C++ the integer constants are evaluated using their original type, which can cause bugs due to integer overflow:
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.
在谷歌转到所有整数评为大整数(没有截断发生), P>
In Google Go, all integers are evaluated as big integers (no truncation happens),
var nanosec_correct int64 = 1000000000 * 600
和没有正常的算术推广
var b int32 = 600
var a int64 = 1000000000 * b
// ^ cannot use 1000000000 * b (type int32) as type int64 in assignment
所以后缀不是必要的。
so the suffixes are not necessary.