E
Eric
Consider the following code:
typedef uint32_t myType_t; // this is an UNSIGNED 32-bit type
myType_t xxx;
Now, what I want to do is load xxx with the maximum possible value
that it can hold, i.e. all bits = 1. How do I do that in a way such
that if the typedef is changed to something other than a 32-bit
unsigned, it will still work?
I can't say "xxx = 0xFFFFFFFF" because that breaks if someone changes
the typedef to "typedef uint16_t myType_t".
I can't say "xxx = -1" because xxx is an unsigned.
Can I use something like:
xxx = 0;
xxx = ~xxx; // bitwise 1's complement
.... or maybe even "xxx = ~0" (bitwise 1's complement of 0)?
Before someone says "Try it and see...", I can't do that until at
least Monday.
Thanks...
typedef uint32_t myType_t; // this is an UNSIGNED 32-bit type
myType_t xxx;
Now, what I want to do is load xxx with the maximum possible value
that it can hold, i.e. all bits = 1. How do I do that in a way such
that if the typedef is changed to something other than a 32-bit
unsigned, it will still work?
I can't say "xxx = 0xFFFFFFFF" because that breaks if someone changes
the typedef to "typedef uint16_t myType_t".
I can't say "xxx = -1" because xxx is an unsigned.
Can I use something like:
xxx = 0;
xxx = ~xxx; // bitwise 1's complement
.... or maybe even "xxx = ~0" (bitwise 1's complement of 0)?
Before someone says "Try it and see...", I can't do that until at
least Monday.
Thanks...