user765443
user765443

Reputation:

change data type between 32 bit to 64 bit

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

Answers (2)

Stephane D.
Stephane D.

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

nogard
nogard

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

Related Questions