本文介绍了是否可以检查您是否正在为64位与微软的C编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有被定义为一个64位版本的一个简单的preprocessor宏?我以为 _WIN64 也许是吧,但即使当我建立一个32位的目标,包含在的#ifdef _WIN64 ...#零件ENDIF 被编译,而这导致的问题。今天是周五,我无法想通,但我敢肯定,我俯瞰这里的东西很简单。甚至一些涉及的sizeof

Is there a simple preprocessor macro that is defined for a 64-bit build? I thought _WIN64 might have been it, but even when I build a 32-bit target, the parts enclosed in a #ifdef _WIN64 ... #endif are compiled in, and this is causing problems. It's Friday and I can't think straight, but I'm sure I'm overlooking something very simple here. Maybe even something involving sizeof.

推荐答案

我一直使用_WIN64来检查它是否是一个64位版本。

I have always used _WIN64 to check if it is a 64 bit build.

N.B。 _WIN32也总是(自动)由MSVC在64位定义的版本,所以检查_WIN64您检查_WIN32之前:

N.B. _WIN32 is also always (automatically) defined by MSVC in 64 bit builds, so check for _WIN64 before you check for _WIN32:

#if defined( _WIN64 )

// Windows 64 bit code here

#elif defined( _WIN32 )

// Windows 32 bit code here

#else

// Non-Windows code here

#endif

这篇关于是否可以检查您是否正在为64位与微软的C编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:43