Reputation:
I need to change the datatype between different OS version in C++. is it possible to define a macro into H file. will it be good practice.
Ex
if os_version=32
long =long
if os_version=64
long =int
Is there any macro/variable which help me to determine that it is 64 bit machine or 32 bit machine
Upvotes: 1
Views: 516
Reputation: 142
I would suggest to use the stdint.h library.
As a matter of fact you are no more using 'int' type but uint32_t for a 32 bits unsigned integer, or uint64_t for a 64 bits unsigned integer.
This library gives you other types. So, by using it, you will not have to be worried about the targeted platform (32/64 bits).
The con is that you will have to change all the types used already into your code, but you will have a code definitely much more portable.
Upvotes: 2
Reputation: 9706
You could use exact-width integer types instead (declared in <cstdint>
)
int8_t
int16_t
int32_t
int64_t
This way the sizes are fixed on all the platforms that provide them.
Upvotes: 4