views:

309

answers:

3

I know Windows uses LLP instead of the LP data model, but is there a predefined variable or something? on OS X/Linux you can use __LP64__.

A: 

Do you really need a preprocessor variable (depending on the case, it might be required, but you may also be able to do without)? Is sizeof(long) == sizeof(void*) not good enough?

Pavel Minaev
@pavel - This is a cross platform app that runs on OS X, Linux and Windows and moving to 64-bit and some Snow Leopard specific items, The logic would certainly be a lot easier to integrate if there was a preprocessor variable. I could use _Win_32 and _Win_64 I suppose since those wont be defined on OS X where LP64 is...
JT
The reason why I asked is because a lot of conditional compilation logic in C++ doesn't really require a preprocessor - you can creatively use templates to produce typedefs, for example. Or just use some stock things, such as `cstdint` header from Boost (as MSVC doesn't have it), and `intptr_t` when you need an integral type that has the same size as pointer on a given platform. It all depends on what specific cases are there in your code that are bitness-specific.
Pavel Minaev
A: 

I don't know if such variable, but you can test for _MSC_VER, which will be defined in Visual Studio. You can then assume an LLP model. If that ever changes in the future, you can use the value of _MSC_VER to test against compiler versions.

If you're looking for standard sized types, check out boost::integer, which defines fixed-bit-sized integer types.

GMan
Correct me if I'm wrong, but this won't disambiguate between 32-bit and 64-bit Windows, only between MSVC and other compilers (and between MSVC versions).Boost seems overkill if this is the only reason for adding it as a dependency for the project. If it's already being used, well, that's cool too.
mrkj
@mrkj: Boost isn't all or nothing. Just grab the necessary header and live free.
GMan
+1  A: 

One way to check is with _WIN64, which is defined only on 64-bit Windows (see here and here). For example:

#if defined(__LP64__)
// LP64 machine, OS X or Linux
#elif defined(_WIN64)
// LLP64 machine, Windows
#else
// 32-bit machine, Windows or Linux or OS X
#endif
mrkj