开发者

How can I dynamically get the system architecture?

Well as the title says

is there any wa开发者_Go百科y to get the system architecture within c++?

Thanks!


Based on "dynamically" and "Visual C++", I'm going to guess you want to do this at run-time under Windows.

In that case, you can use GetSystemInfo or GetNativeSystemInfo to retrieve some basic information about the system and processor. If you need more information about the processor and specific features it supports, you can use IsProcessorFeaturePresent to find them (though it can be a little awkward for this purpose -- you have to ask about each feature individually, and gives a Boolean answer for each).


#if defined(_M_X64)
...
#endif


There's a nice big list here. The macros are different for Visual Studio and GCC, but just check if they're defined with #ifdef.

Something like:

#if defined(_M_IX86) || defined(__i386__)

Should give you GCC, Visual Studio, and several others.


You can always mix in a few lines of inline assembly and call CPUID to identify the CPU your code is executing on. See this paper as for how to do it:

http://www.intel.com/Assets/PDF/appnote/241618.pdf


On x64 platforms sizeof(void*) returns 8. On x32 platforms sizeof(void*) returns 4. This should also be cross platform.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜