Search code examples
cc-preprocessorunsigned

Why use #define DEF ((unsigned) -1) instead of #define 0xFFFFFFFF


In the C language, why use the following line to define a constant with all bits set to 1?:

#define EXTENDED_MEM_END    ((unsigned) -1)

Instead of using the following?:

#define EXTENDED_MEM_END    0xFFFFFFFF

Or just this?:

#define EXTENDED_MEM_END    -1

Does it have something to do with portability (i.e., avoiding warnings), with a very specific code, and/or something else?

I suspect that, since the C code is going to have the EXTENDED_MEM_END identifier replaced by ((unsigned) -1), it is in fact a way to use the correct/expected value.


Solution

  • #define EXTENDED_MEM_END    0xFFFFFFFF
    

    isn't right if ints aren't 32 bits;

    #define EXTENDED_MEM_END    -1
    

    isn't unsigned.