I found both long int long
and int long long
can compile for a variable type. Is there any difference between long int long
, int long long
, long long
and long long int
?
我发现,long int long和int long都可以编译为变量类型。长、长、长、长、长、长,有什么区别吗?
In general, is the type identical if it has the same number of long
?
一般来说,如果类型具有相同的长数,类型是否相同?
1 long:
1长:
long l;
int long il;
long int li;
2 long:
2长:
long long ll;
int long long ill;
long int long lil;
long long int lli;
Also if above is right, are the following declarations also identical?
同样,如果上面是对的,下面的声明是否也是相同的?
long long* llp;
int long long* illp;
long int long* lilp;
long long int* llip;
4 个解决方案
#1
128
According to the C++ Standard (7.1.6.2 Simple type specifiers)
根据c++标准(7.1.6.2简单类型说明符)
3 When multiple simple-type-specifiers are allowed, they can be freely intermixed with other decl-specifiers in any order.
当允许多个简单类型的说明符时,它们可以*地与其他的decl- speciator混合在一起。
So for example the following declaration is valid
例如,下面的声明是有效的。
long static long const int x = 10;
You may even use constexpr
specifier along with const
qualifier. For example
您甚至可以使用constexpr说明符和const限定符。例如
constexpr long static long const int x = 10;
By the way, we forgot about specifier signed
! Let's add it for example before declarator x
顺便说一下,我们忘记了签名的说明符!比如在x声明符之前
constexpr long static long const int signed x = 10;
In C you may also use several type qualifiers in the same declare specifier sequence. According to the C Standard (6.7.3 Type qualifiers)
在C中,您还可以在相同的声明说明符序列中使用多个类型限定符。根据C标准(6.7.3类型限定符)
5 If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once....
5如果相同的限定符出现在同一specifier-qualifier-list不止一次,直接或通过一个或多个typedef,行为是一样的如果它....只出现一次
So for example in C the following declaration is also valid
例如在C中,下面的声明也是有效的
const long const long static const int const signed x = 10;
So if you are paid according to the number of symbols typed in the program then I advise you to use such declarations. :)
因此,如果你是根据程序中输入的符号数量来支付报酬的,那么我建议你使用这些声明。:)
#2
107
Is the type identical...
类型是相同的…
Yes.
是的。
C++11 §7.1.6.2/3
c++ 11§7.1.6.2/3
” When multiple simple-type-specifiers are allowed, they can be freely intermixed with other decl-specifiers in any order.
“当允许多个简单类型说明符时,它们可以任意顺序地与其他decl说明符混合。”
#3
40
Yes, but please don't. Just as English and German have conventional word orders for adjectives and adverbs (e.g. time - manner - place), so do C and C++. Varying from the conventional order won't confuse the compiler, but it will confuse your fellow developers. I would suggest that the conventional order is roughly along the lines of
是的,但是请不要。正如英语和德语对形容词和副词(例如:time - way - place)有传统的词序一样,C和c++也是如此。与常规顺序不同不会让编译器感到困惑,但会让您的开发伙伴感到困惑。我认为传统的秩序大致是沿着这条线的。
-
static
/extern
(linkage) - 静态/走读生(链接)
-
const
/volatile
(modification) - const /不稳定(修改)
-
signed
/unsigned
(signedness) - 签署/无符号(signedness)
-
short
/long
(length) - 短/长(长度)
- Basic type (head noun)
- 基本类型(名词)
although there's certainly some wiggle room.
尽管有一些回旋的余地。
#4
27
Is “long long” = “long long int” = “long int long” = “int long long”?
“long long long long long long int”=“long long long long int long int long long long”=“long int long long long long long long long long long long long long long long long long long long long long long long long long long long long int”?
All other answers here talked about the second part of your question. For the first part: Is “long long” = “long long int” ?, answer is yes.
这里所有的答案都是关于你问题的第二部分。第一部分:“long long long long long long”=“long long long long long long long int”?
C++11 7.1.6.2 Simple type specifiers (table 10)
Specifier(s) Type
... ...
long long int “long long int”
long long “long long int”
long int “long int”
long “long int”
... ...
For the second part of your question: Is “long int long” = “int long long”?, answer is yes again.
对于你问题的第二部分:“long int long”=“int long long”?答案是肯定的。
The type-specifiers may occur in any order and can be intermixed with the other declaration specifiers. Therefore, all of the following
类型说明符可以以任何顺序出现,并且可以与其他声明说明符混合。因此,有以下几点
long long
long long int
long int long
int long long
are valid and equivalent.
是有效的和等价的。
#1
128
According to the C++ Standard (7.1.6.2 Simple type specifiers)
根据c++标准(7.1.6.2简单类型说明符)
3 When multiple simple-type-specifiers are allowed, they can be freely intermixed with other decl-specifiers in any order.
当允许多个简单类型的说明符时,它们可以*地与其他的decl- speciator混合在一起。
So for example the following declaration is valid
例如,下面的声明是有效的。
long static long const int x = 10;
You may even use constexpr
specifier along with const
qualifier. For example
您甚至可以使用constexpr说明符和const限定符。例如
constexpr long static long const int x = 10;
By the way, we forgot about specifier signed
! Let's add it for example before declarator x
顺便说一下,我们忘记了签名的说明符!比如在x声明符之前
constexpr long static long const int signed x = 10;
In C you may also use several type qualifiers in the same declare specifier sequence. According to the C Standard (6.7.3 Type qualifiers)
在C中,您还可以在相同的声明说明符序列中使用多个类型限定符。根据C标准(6.7.3类型限定符)
5 If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once....
5如果相同的限定符出现在同一specifier-qualifier-list不止一次,直接或通过一个或多个typedef,行为是一样的如果它....只出现一次
So for example in C the following declaration is also valid
例如在C中,下面的声明也是有效的
const long const long static const int const signed x = 10;
So if you are paid according to the number of symbols typed in the program then I advise you to use such declarations. :)
因此,如果你是根据程序中输入的符号数量来支付报酬的,那么我建议你使用这些声明。:)
#2
107
Is the type identical...
类型是相同的…
Yes.
是的。
C++11 §7.1.6.2/3
c++ 11§7.1.6.2/3
” When multiple simple-type-specifiers are allowed, they can be freely intermixed with other decl-specifiers in any order.
“当允许多个简单类型说明符时,它们可以任意顺序地与其他decl说明符混合。”
#3
40
Yes, but please don't. Just as English and German have conventional word orders for adjectives and adverbs (e.g. time - manner - place), so do C and C++. Varying from the conventional order won't confuse the compiler, but it will confuse your fellow developers. I would suggest that the conventional order is roughly along the lines of
是的,但是请不要。正如英语和德语对形容词和副词(例如:time - way - place)有传统的词序一样,C和c++也是如此。与常规顺序不同不会让编译器感到困惑,但会让您的开发伙伴感到困惑。我认为传统的秩序大致是沿着这条线的。
-
static
/extern
(linkage) - 静态/走读生(链接)
-
const
/volatile
(modification) - const /不稳定(修改)
-
signed
/unsigned
(signedness) - 签署/无符号(signedness)
-
short
/long
(length) - 短/长(长度)
- Basic type (head noun)
- 基本类型(名词)
although there's certainly some wiggle room.
尽管有一些回旋的余地。
#4
27
Is “long long” = “long long int” = “long int long” = “int long long”?
“long long long long long long int”=“long long long long int long int long long long”=“long int long long long long long long long long long long long long long long long long long long long long long long long long long long long int”?
All other answers here talked about the second part of your question. For the first part: Is “long long” = “long long int” ?, answer is yes.
这里所有的答案都是关于你问题的第二部分。第一部分:“long long long long long long”=“long long long long long long long int”?
C++11 7.1.6.2 Simple type specifiers (table 10)
Specifier(s) Type
... ...
long long int “long long int”
long long “long long int”
long int “long int”
long “long int”
... ...
For the second part of your question: Is “long int long” = “int long long”?, answer is yes again.
对于你问题的第二部分:“long int long”=“int long long”?答案是肯定的。
The type-specifiers may occur in any order and can be intermixed with the other declaration specifiers. Therefore, all of the following
类型说明符可以以任何顺序出现,并且可以与其他声明说明符混合。因此,有以下几点
long long
long long int
long int long
int long long
are valid and equivalent.
是有效的和等价的。