C++ 类型 unsigned long int
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11779704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ type unsigned long int
提问by Anders Lind
Is unsigned long int
equivlant to unsigned long
?
in C++
是 unsigned long int
equivlant来unsigned long
?在 C++ 中
In my opinion they are same. But I saw some people still using unsigned long int in code. Don't understand why? Could anybody explain it for me
在我看来,它们是一样的。但是我看到有些人仍然在代码中使用 unsigned long int。不明白为什么?谁能给我解释一下
#include <stdio.h>
int main() {
unsigned long int num = 282672;
int normalInt = 5;
printf("");
return 0;
}
回答by
Yes.
是的。
long
is just a shorthand for long int
. This is because in principle long
is just a qualifier (it can also be used for prolonging a double
datatype, for example)
long
只是 的简写long int
。这是因为原则long
上只是一个限定符(例如,它也可以用于延长double
数据类型)
From C++ ISO Standard, section 7.1.5.2, a table of equivalent type specifiers:
来自 C++ ISO 标准的第 7.1.5.2 节,等效类型说明符表:
回答by Hristo Iliev
§6.7.2 of the C99 standard gives the following list of types (this is only an excerpt):
C99 标准的 §6.7.2 给出了以下类型列表(这只是摘录):
short
,signed short
,short int
, orsigned short int
unsigned short
, orunsigned short int
int
,signed
, orsigned int
unsigned
, orunsigned int
long
,signed long
,long int
, orsigned long int
unsigned long
, orunsigned long int
long long
,signed long long
,long long int
, orsigned long long int
unsigned long long
, orunsigned long long int
short
,signed short
,short int
, 或signed short int
unsigned short
, 或者unsigned short int
int
,signed
, 或signed int
unsigned
, 或者unsigned int
long
,signed long
,long int
, 或signed long int
unsigned long
, 或者unsigned long int
long long
,signed long long
,long long int
, 或signed long long int
unsigned long long
, 或者unsigned long long int
with the following additional point:
有以下附加点:
(5) Each of the comma-separated sets designates the same type, except that for bit-fields, it is implementation-defined whether the specifier
int
designates the same type assigned int
or the same type asunsigned int
.
(5) 每个逗号分隔的集合指定相同的类型,除了位域之外,说明符
int
指定与 相同的类型signed int
还是与 相同的类型是实现定义的unsigned int
。
回答by Sebastian Mach
Yes. unsigned
, signed
, short
, long
, long long
all are simple type specifiers for XXX int
.
是的。unsigned
, signed
, short
, long
,long long
都是 的简单类型说明符XXX int
。
See 7.1 Specifiers [dcl.spec]in the standard:
参见标准中的7.1 说明符 [dcl.spec]:
3 [ Note: Since signed, unsigned, long, and short by default imply int, a type-name appearing after one of those specifiers is treated as the name being (re)declared. [ Example:
void h(unsigned Pc); // void h(unsigned int)
void k(unsigned int Pc); // void k(unsigned int)
—end example ] —end note ]
3 [ 注意:由于默认情况下有符号、无符号、长整型和短整型都表示 int,因此出现在这些说明符之一之后的类型名称将被视为(重新)声明的名称。[ 例子:
void h(unsigned Pc); // void h(unsigned int)
void k(unsigned int Pc); // void k(unsigned int)
—结束示例] —结束注释]
and 7.1.6.2 Simple type specifiers [dcl.type.simple]
和7.1.6.2 简单类型说明符 [dcl.type.simple]
Table 10 — simple-type-specifiers and the types they specify
Specifier(s) | Type
------------------------+---------------------------------
type-name | the type named
simple-template-id | the type as defined in 14.2
char | “char”
unsigned char | “unsigned char”
signed char | “signed char”
char16_t | “char16_t”
char32_t | “char32_t”
bool | “bool”
unsigned | “unsigned int”
unsigned int | “unsigned int”
signed | “int”
signed int | “int”
int | “int”
unsigned short int | “unsigned short int”
unsigned short | “unsigned short int”
unsigned long int | “unsigned long int”
unsigned long | “unsigned long int”
unsigned long long int | “unsigned long long int”
unsigned long long | “unsigned long long int”
signed long int | “long int”
回答by trojanfoe
unsigned long int
is the correct type definition, however int
can be ignored.
unsigned long int
是正确的类型定义,但是int
可以忽略。
回答by NX1
Yes, they are the same. Saying unsigned long int
is simply explicitly stating that it is an int.
是的,它们是一样的。说unsigned long int
只是明确说明它是一个整数。
You can always look at the size of the type by sizeof(unsigned long int)
and sizeof(unsigned long)
您始终可以通过sizeof(unsigned long int)
和查看类型的大小sizeof(unsigned long)
Hope this helps.
希望这可以帮助。