A question was recently asked about whether ULL
or LLU
was valid for specifying unsigned long long constants in C. I know they\'re both valid but I
The ISO C11 standard states in 6.2.5 Types
:
There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int.
For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned) that uses the same amount of storage (including sign information) and has the same alignment requirements.
However there's no mandate in that section as to the order in which the base type and unsigned
modifier appears.
The controlling section is later in the standard, 6.7.2 Type specifiers
, paraphrased here:
Type specifiers are
void
,char
,short
,int
,long
,float
,double
,signed
,unsigned
,_Bool
,_Complex
,<struct-or-union-specifier>
,<enum-specifier>
, and<typedef-name>
.At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
It then goes on to list all the multisets, such as unsigned long, or unsigned long int
.
But the important phrase there is the type specifiers may occur in any order
, meaning that all of these are valid for that multiset:
unsigned long
long unsigned
unsigned long int
unsigned int long
long unsigned int
long int unsigned
int unsigned long
int long unsigned
The order of the specifier dosen't matter.
unsigned long long is the same as long long unsigned.
Both types are valid according to C standard(c99).