Re:What is a safest way to set all bits of a variable to tru...
by senki on Monday October 11, 2010 @04:58AM
(#1779200)
The "limits.h" (ISO C99 Standard) defines UINT_MAX as the maximum value for a variable of type unsigned int which is 4294967295 (0xffffffff).
[ Parent
| on HN ]
Re:What is a safest way to set all bits of a variable to tru...
by sfk on Monday October 11, 2010 @06:26AM
(#1779305)
Sigh:
"The contents of the header <limits.h> are given below, in alphabetical order. The minimum magnitudes shown shall be replaced by implementation-defined magnitudes with the same sign."
#define UINT_MAX 65535
Key here is implementation-defined, with a minimum of 65535.
Re:What is a safest way to set all bits of a variable to tru...
by senki on Monday October 11, 2010 @07:11AM
(#1779370)
Platforms differ, and the limits.h reflects this, that's the point. We should use the abstractions (the #defines) of the standard library, i.e. refer to these values by their names, that's the way to write portable software.
Re:What is a safest way to set all bits of a variable to tru...
by protomyth on Monday October 11, 2010 @10:14AM
(#1779766)
I always though that was set by the vendor correctly. Oh well..
I always liked the definition of true in Forth (all bits set to 1). It really made it a lot easier.
Re:What is a safest way to set all bits of a variable to tru...
by tedunangst on Monday October 11, 2010 @01:47PM
(#1780483)
The standard doesn't require that an int use all of the bits of storage it takes. A hypothetical 33-bit machine may present a C environment where ints are 32-bits, with the extra bit unused (and unset).