Reputation: 13908
I have a C++ pre-processor directive that is something like this:
#if (SOME_NUMBER != 999999999999999)
// do stuff
#endif
999999999999999 is obviously greater than 232, so the value won't fit into a 32-bit integer. Will the preprocessor correctly use a 64-bit integer to resolve the comparison, or will it truncate one or both of the values?
Upvotes: 4
Views: 629
Reputation: 57046
Preprocessor arithmetic works as normal constant expressions (see the Standard, 16.1/4), except that int
and unsigned int
are treated as if they were long
and unsigned long
. Therefore, if you have a 64-bit type, you can use it as normal.
Upvotes: 1
Reputation: 52668
You can try using the UINT_MAX
constant defined in "limits.h":
#if (SOME_NUMBER != UINT_MAX)
// do stuff
#endif
UINT_MAX
value varies depending on the integer size.
Upvotes: 1
Reputation: 4827
Try to use the LL suffix:
#if (SOME_NUMBER != 999999999999999LL)
// do stuff
#endif
In my gcc this work fine:
#include <iostream>
#define SOME_NUMBER 999999999999999LL
int main()
{
#if (SOME_NUMBER != 999999999999999LL)
std::cout << "yes\n";
#endif
return 0;
}
With or without the LL suffix.
Upvotes: 2