1

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 ?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
AnonBird
  • 570
  • 13
  • 27
  • 1
    See https://stackoverflow.com/questions/1171839/what-is-the-unsigned-datatype : unsigned really is a shorthand for unsigned int – jaudo Jun 17 '19 at 15:28
  • Possible duplicate of [what is the unsigned datatype?](https://stackoverflow.com/questions/1171839/what-is-the-unsigned-datatype) – jaudo Jun 17 '19 at 15:45

1 Answers1

4

Accoprding to the C Standard (6.7.2 Type specifiers, p.#2)

  1. ...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 ).

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335