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.
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 .
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 .
int is 32 bits. long is 32 bits as well. long long is 64 bits.
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.
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”
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With