是否可以检查您是否正在使用 Microsoft C 编译器为 64 位构建? [英] Is it possible to check whether you are building for 64-bit with Microsoft C Compiler?

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

问题描述

是否有为 64 位构建定义的简单预处理器宏?我认为 _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.

注意_WIN32 也总是(自动)由 MSVC 在 64 位版本中定义,因此在检查 _WIN32 之前先检查 _WIN64:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆