If I do:
#define TIMEFIXCONST 11644473600
on a 32bit machine, will it overflow or will it be stored as a long long and still work properly? Should I just define a global unsigned long long and use that instead?
If I do:
#define TIMEFIXCONST 11644473600
on a 32bit machine, will it overflow or will it be stored as a long long and still work properly? Should I just define a global unsigned long long and use that instead?
If you store this in an int
, it will overflow on both x64 and x86. If you store it in a long
, you wont have the problem on either platform. The #define
has no bearing on memory.
A (non?)standard way to do that would be
#define TIMEFIXCONST 11644473600LL
Then it will be treated as "long long". What happens after that depends on the statement you use it in (overflow, etc). If you try to assign it to a 32-bit variable it will get truncated and the compiler should throw a warning.
A macro is only a text substitution, you can't overflow a macro.
It depends on where do you assign later TIMEFIXCONST.
But as a rule of thumb, when using constants use const int
or const long long
if you require.
The number is not "stored" anywhere. It will just be inserted in the program source code where you use the macro, just as if you had written it directly. But if you want the literal itself to be of type long long, write:
#define TIMEFIXCONST 11644473600LL