On a 32 bits system, what is the behavior of a simple unsigned
cast ?
For example, let's say I have a long var = 1
, would (unsigned)var
cast it to an unsigned long
or an unsigned int
?
On a 32 bits system, what is the behavior of a simple unsigned
cast ?
For example, let's say I have a long var = 1
, would (unsigned)var
cast it to an unsigned long
or an unsigned int
?
Accoprding to the C Standard (6.7.2 Type specifiers, p.#2)
- ...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.
...
— unsigned, or unsigned int
...
— unsigned long, or unsigned long int
So the type specifier in the cast expression ( unsigned )
denotes the type unsigned int
.
If you want to cast to unsigned long
then you should write either ( unsigned long )
or ( usigned long int )
. And as it is written in the quote you may use any order of type specifiers as for example ( int long unsigned )
.