Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abbreviated type name long long vs long long int, is it standard-compliant?

Most of the code I see use abbreviated types to declare a variable, such as

long long x; // long long int x
short y; // short int y

I skimmed through the C++11 standard (Sec. 3.9.1) and the type is always declared fully, as long long int. I couldn't find any mentioning of abbreviated types. I am pretty sure the abbreviations are standard-compliant, but wanted to make sure if this is indeed the case. So my question is whether the above code is fully standard compliant.

like image 987
vsoftco Avatar asked Jan 26 '15 16:01

vsoftco


People also ask

Is long long int same as long long?

long and long int are identical. So are long long and long long int . In both cases, the int is optional. As to the difference between the two sets, the C++ standard mandates minimum ranges for each, and that long long is at least as wide as long .

What are the differences between int long long long and short?

All store integers, but consume different memory and have different ranges. For eg: short int consumes 16bits, long int consumes 32bits and long long int consumes 64bits. The maximum value of short int is 32767. So of you need to store big values you need to use long int .

What is the difference between long int and long long int?

int is 32 bits. long is 32 bits as well. long long is 64 bits.

Is int64 same as long long?

Anyway, there is no real difference between the two: as you said, both are used to create a 64 bit integer... on today's 32 bit platforms. While __int64 is probably guaranteed to always implement 64 bit integers (due to its name), long long is not tied to a particular bit size.


2 Answers

Yes, this is valid it is covered in the draft C++11 standard section 7.1.6.2 Simple type specifiers which says:

Table 10 summarizes the valid combinations of simple-type-specifiers and the types they specify.

and in Table 10 simple-type-specifiers and the types they specify says:

long long      “long long int”

and:

short          “short int”
like image 184
Shafik Yaghmour Avatar answered Sep 20 '22 17:09

Shafik Yaghmour


Yes it is. But, since, C++99 it's far better to use the sized types

std::int8_t
std::int16_t
std::int32_t
std::int64_t

and their unsigned cousins std::uint8_t etc whenever possible. Then you know what you're dealing with.

Note that compilers don't have to support the 64 bit integral types.

like image 36
Bathsheba Avatar answered Sep 22 '22 17:09

Bathsheba