vsoftco
vsoftco

Reputation: 56547

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.

Upvotes: 5

Views: 3204

Answers (3)

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158469

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”

Upvotes: 6

Bathsheba
Bathsheba

Reputation: 234665

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.

Upvotes: 2

Sebastian Redl
Sebastian Redl

Reputation: 71919

Yes, see table 10 in 7.1.6.2, which defines the mapping from various specifier combinations to the types from 3.9.

Upvotes: 1

Related Questions