跨平台开发,各种宏的定义

gcc跨平台开发,各种宏的定义,_WIN32,__linux,__unix


Re: Cross platform code

From: Oleg Goldshmidt (pub_at_nonexisting.hamakor.org.il)
Date: Fri 04 Jul 2003 - 03:09:22 IDT

* Next message: Orna Agmon: "[HAIFUX LECTURE] from python import lecture, by Muli Ben-Yehuda"
* Previous message: Shachar Shemesh: "Re: Cross platform code"
* In reply to: Gilboa Davara: "Re: Cross platform code"
* Next in thread: Gilboa Davara: "Re: Cross platform code"
* Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
* Mail actions: [ respond to this message ] [ mail a new topic ]

Gilboa Davara <gilboa_at_xml-systems.com> writes:

> CPP/GCC/CC all define _WIN32 by default under all the environment I ever
> worked on. (which is pretty extensive.)

Really? Right now I am in an environment where several different
version of cpp and gcc don‘t define that. It seems to me that the
range of environments where gcc defines _WIN32 is pretty narrow.

To complement that, I have no idea what you mean by CPP or CC.

> By design, compilers running under Windows (be that Watcom, Borland or
> MCVC) must define _WINTVER, _WIN32 and M_IX86/M_ALPA/etc in-order to
> include the Winxxx.h files. (which are required to access any OS
> functions)

That‘s fine, this is exactly one platform that we have covered in the
passage above.

> So yes, these are compiler defined macros that can be relayed upon.

Yes, indeed. However, I know of no rule that says that, e.g., unix must
be defined for any of the unices or for Linux, as the snippet of your
earlier mail that follows below seems to imply.

On my RH7.3 gcc does define unix, __unix, __unix__, linux, __linux,
and __linux__. However, it is enough to use the -ansi option to
make unix and linux disappear. There you go.

None of the standard glibc or glibc-kernel headers (meaning
linux-specific headers exposed to applications programmers) uses unix,
__unix, or __unix__ (some applications do, but it‘s their
business). This tells me that gcc only uses those internally, and not
to access any library or system facilities. This means that there may
be compilers that will not define these macros and still work just
fine.

Gilboa Davara <gilboa_at_xml-systems.com> writes:

> Better yet:
>
> #ifdef unix
>
> // UNIX/Linux/*BSD.
>
> #endif
>
> #ifdef _WIN32
>
> // Window stuff
>
> #endif
>
> Both symbols are auto defined by the compiler.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值