哪个跨平台预处理器定义? (__WIN32__或__WIN32或WIN32)? [英] Which Cross Platform Preprocessor Defines? (__WIN32__ or __WIN32 or WIN32 )?

查看:1130
本文介绍了哪个跨平台预处理器定义? (__WIN32__或__WIN32或WIN32)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到 __ WIN32 WIN32 __ WIN32 __ 。我假设这取决于使用的预处理器(从visual studio或gcc等)。

I often see __WIN32, WIN32 or __WIN32__. I assume that this depends on the used preprocessor (either one from visual studio, or gcc etc).

我现在必须首先检查os,然后为使用编译器?我们在这里使用G ++ 4.4.x,Visual Studio 2008和Xcode(我假设是一个gcc)和ATM我们只使用 __ WIN32 __ __APPLE __ __ LINUX __

Do I now have to check first for os and then for the used compiler? We are using here G++ 4.4.x, Visual Studio 2008 and Xcode (which I assume is a gcc again) and ATM we are using just __WIN32__, __APPLE__ and __LINUX__.

推荐答案

取决于你想要做什么。如果您的程序想要使用一些特定的函数(例如从gcc工具链),可以检查编译器。如果要使用某些特定于操作系统的函数(不考虑编译器,例如Windows上的CreateProcess和unix上的fork),可以检查操作系统(_WINDOWS,__unix__)。

It depends what you are trying to do. You can check the compiler if your program wants to make use of some specific functions (from the gcc toolchain for example). You can check for operating system ( _WINDOWS, __unix__ ) if you want to use some OS specific functions (regardless of compiler - for example CreateProcess on Windows and fork on unix).

Visual C的宏

gcc的宏

您必须检查每个编译器的文档,以便能够在编译时检测差异。我记得gnu工具链(gcc)在C库中有一些功能( libc ),不在其他工具链上(例如Visual C)。这样,如果你想使用那些功能的商品,那么你必须检测到你使用GCC,所以你必须使用的代码如下:

You must check the documentation of each compiler in order to be able to detect the differences when compiling. I remember that the gnu toolchain(gcc) has some functions in the C library (libc) that are not on other toolchains (like Visual C for example). This way if you want to use those functions out of commodity then you must detect that you are using GCC, so the code you must use would be the following:

#ifdef __GNUC__
// do my gcc specific stuff
#else
// ... handle this for other compilers
#endif

这篇关于哪个跨平台预处理器定义? (__WIN32__或__WIN32或WIN32)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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