I am working with a library that defines a constant like this:
#define SOME_BIG_CONSTANT 0x0000000100000000
This literal is too large to be represented as long
, so any program that uses this macro fails to compile (using gcc 4.1.2 for VxWorks). The (non-standard, but supported by this compiler) solution that works is to add the suffix ull
to the literal:
#define SOME_BIG_CONSTANT 0x0000000100000000ull
However, that would require me to modify the library-header, which I'd rather not do. I suck at macros, so my question is, how can I define a macro that would add that suffix, which I could call like this:
ULL_(SOME_BIG_CONSTANT)
Which would expand to:
0x0000000100000000ull
ull is a standard suffix on C++11.
On the other hand, you may define the following macros:
#define APPEND(x, y) x ## y
#define ULL(x) APPEND(x, ull)
Now, you can use:
int main()
{
unsigned long long a = ULL(SOME_BIG_CONSTANT);
return 0;
}
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