Is there a way to make enum
type to be unsigned? The following code gives me a warning about signed/unsigned comparison.
enum EEE {
X1 = 1
};
int main()
{
size_t x = 2;
EEE t = X1;
if ( t < x ) std::cout << "ok" << std::endl;
return 0;
}
I've tried to force compiler to use unsigned underlying type for enum with the following:
enum EEE {
X1 = 1,
XN = 18446744073709551615LL
// I've tried XN = UINT_MAX (in Visual Studio). Same warning.
};
But that still gives the warning.
Changing constant to UINT_MAX
makes it working in GNU C++ as should be according to the standard. Seems to be a bug in VS. Thanks to James for hint.
You might try:
enum EEE {
X1 = 1,
XN = -1ULL
};
Without the U
, the integer literal is signed.
(This of course assumes your implementation supports long long
; I assume it does since the original question uses LL
; otherwise, you can use UL
for a long
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With