1. ## ((uint32_t)(~0UL)) ??

Can anyone explain this definition?

Code:
```#include <stdint.h>
#include <stdbool.h>

#define NULL_BLOCK ((uint32_t)(~0UL))```

2. Recall that ~ is the bitwise complement operator.

3. ~0UL means that complement of 0 is to be interpreted as an unsigned long explicitly casted as an unsigned int.

~0UL = 4294967295 or 0xffffffff

Thats the largest value that can be in a 32 bit integer.

4. Originally Posted by Syscal
~0UL means that complement of 0 is to be interpreted as an unsigned long explicitly casted as an unsigned int.

~0UL = 4294967295 or 0xffffffff

Thats the largest value that can be in a 32 bit integer.
Thank you.
Where can I find information about these conventions?

5. Originally Posted by frs
Where can I find information about these conventions?
If you are talking about the values, then you can #include <limits.h> and check the constants, though in this case it would have been simpler to just print the result out to verify the value for yourself.

If you are talking about the meaning of the expression, then as I noted it is about knowing what ~ means (and of course the cast).

6. I wonder though if it's actually valid. I don't think so: "0UL" is not guaranteed to be 32 bits is it? Or is it guaranteed to be at least 32 bits? If not, say a long may be 16 bits, then 0UL may be 16 bits, and ~0UL would have 16 bits set to 1, and casting it to uint32_t won't change this...

So my question to those who know a bit more about the strict specification: is this actually legal?

7. so 14UL is the same as (unsigned long)14?? I'm talking about the syntax, 0UL, never seen a cast made that way.

Originally Posted by laserlight
If you are talking about the values, then you can #include <limits.h> and check the constants, though in this case it would have been simpler to just print the result out to verify the value for yourself.

If you are talking about the meaning of the expression, then as I noted it is about knowing what ~ means (and of course the cast).

8. Originally Posted by EVOEx
II wonder though if it's actually valid. I don't think so: "0UL" is not guaranteed to be 32 bits is it? Or is it guaranteed to be at least 32 bits? If not, say a long may be 16 bits, then 0UL may be 16 bits, and ~0UL would have 16 bits set to 1, and casting it to uint32_t won't change this...
As a consequence of the minimum range of an unsigned long, an unsigned long object must be at least 32 bits in size.

Originally Posted by frs
so 14UL is the same as (unsigned long)14?? I'm talking about the syntax, 0UL, never seen a cast made that way.
Ah. In terms of value and type, yes. It is not a cast; it is a way of specifying that the integer constant is of type unsigned long.

9. Originally Posted by laserlight
Ah. In terms of value and type, yes. It is not a cast; it is a way of specifying that the integer constant is of type unsigned long.
Hmm, thank you once again.