How can I detect if I'm compiling for a 64bits architecture in C++

前端 未结 8 1711
难免孤独
难免孤独 2020-12-29 23:07

In a C++ function I need the compiler to choose a different block if it is compiling for a 64 bit architecture.

I know a way to do it for MSVC++ and g++, so I\'ll po

8条回答
  •  不思量自难忘°
    2020-12-29 23:22

    Why are you choosing one block over the other? If your decision is based on the size of a pointer, use sizeof(void*) == 8. If your decision is based on the size of an integer, use sizeof(int) == 8.

    My point is that the name of the architecture itself should rarely make any difference. You check only what you need to check, for the purposes of what you are going to do. Your question does not cover very clearly what your purpose of the check is. What you are asking is akin to trying to determine if DirectX is installed by querying the version of Windows. You have more portable and generic tools at your disposal.

提交回复
热议问题