0LL 或 0x0UL 是什么意思? [英] What do 0LL or 0x0UL mean?

查看:53
本文介绍了0LL 或 0x0UL 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Google Go 教程,并在常量部分看到了这一点:

I am reading the Google Go tutorial and saw this in the constants section:

没有像 0LL 或 0x0UL 这样的常量

There are no constants like 0LL or 0x0UL

我尝试进行 Google 搜索,但出现的只是人们使用这些常量但没有解释它们的含义的实例.0x 应该以十六进制文字开头,但这些不是十六进制数字中可能出现的字符.

I tried to do a Google search but all that comes up are instances where people are using these constants but no explanation as to what they mean. 0x is supposed to start a hexadecimal literal but these are not characters that are possible in a hexadecimal number.

推荐答案

这些是 C 和 C++ 中的常量.后缀LL 表示常量是long long 类型,UL 表示unsigned long.

These are constants in C and C++. The suffix LL means the constant is of type long long, and UL means unsigned long.

一般来说,每个Ll代表一个long,而每个Uu 表示 无符号.所以,例如

In general, each L or l represents a long and each U or u represents an unsigned. So, e.g.

1uLL

表示unsigned long long类型的常量1.

这也适用于浮点数:

1.0f    // of type 'float'
1.0     // of type 'double'
1.0L    // of type 'long double'

还有字符串和字符,但它们是前缀:

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.

在 Google Go 中,所有整数都被评估为大整数(不会发生截断),

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

所以后缀不是必需的.

这篇关于0LL 或 0x0UL 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆