3 ms·
Better example: #define FLAG_63 (1ULL << 63) long long flags = FLAG_63; In this case, if (flags & FLAG_63) pass(); will pass, but typedef int BOOL;
by hun3 3y ago
Better example:
#define FLAG_63 (1ULL << 63)
long long flags = FLAG_63;
In this case,
if (flags & FLAG_63) pass();
will pass, but
typedef int BOOL;
BOOL set = flags & FLAG_63;
if (set) pass();
won't pass, due to truncation.
Question: Would you argue that a datatype that holds the smallest (1-bit) datum should be as wide as the largest integer type just to handle such cases?
If so, that would be highly inefficient for storage purposes. Note that Win32 has 32-bit BOOL type, but internally NT uses 8-bit BOOLEAN type to store bools in structures.