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

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.
 

你可能感兴趣的:(linux,unix,gcc,Borland,跨平台,macros)