I came across a code like below:
#define SOME_VALUE 0xFEDCBA9876543210ULL
This SOME_VALUE is assigned to some unsigned long long later.
Questions:
- Is there a need to have postfix like
ULLin this case ? - What are the situation we need to specify the type of integer used ?
- Do C and C++ behave differently in this case ?
In C, a hexadecimal literal gets the first type of
int,unsigned int,long,unsigned long,long longorunsigned long longthat can represent its value if it has no suffix. I wouldn’t be surprised if C++ has the same rules.You would need a suffix if you want to give a literal a larger type than it would have by default or if you want to force its signedness, consider for example
Without suffix, that is (almost certainly) undefined behaviour, but
1LL << 43;for example would be fine.