Why is __unix__ defined, and not __WINDOWS__ ?

Brian Inglis Brian.Inglis@SystematicSw.ab.ca
Mon May 13 05:40:00 GMT 2019


On 2019-05-12 22:12, Agner Fog wrote:
> On 12/05/2019 21.53, Hans-Bernhard Bröker wrote:
>> Am 12.05.2019 um 20:22 schrieb Agner Fog:
>>> I have noticed that the gcc and clang compilers have defined the
>>> preprocessing macro __unix__, but not __WINDOWS__, _WIN32, or _WIN64
>>> when compiling a windows executable.
>>> Why is this?
>> Because it's correct that way.  Cygwin runs on Windows, but it _is_ not
>> Windows.
>>> A C/C++ program will check for these macros if it wants to know which
>>> operating system you are compiling for, and this will give the wrong
>>> result.
>> No.  It gives the correct result.> But the compiler generates a Windows executable following most of the
> Windows ABI (object file format, calling convention, etc.)
Not quite I believe Cygwin 64 bit programs follow the Unix 64 bit LP64 C
programming memory model and the System V AMD64 ABI *NOT* the Windows 64 bit
ILP64 C programming memory model and Microsoft x64 calling convention; see:
	http://www.unix.org/version2/whatsnew/lp64_wp.html
	https://en.wikipedia.org/wiki/X86_calling_conventions
- the interface has to be managed by the Cygwin1 dll.

On 32 bit the Unix and Windows C programming memory models are both ILP32 I
believe, but Cygwin does not support the Pascal left to right argument calling
convention and callee pop, and probably handles registers differently.

The Cygwin host, build, target platform triplets are
{x86_64,i686}-{pc-cygwin,w64-mingw32} - the OS is Cygwin or Mingw, neither Unix
nor Windows.

If a Cygwin build defines Windows macros, few GNU, BSD, or other Unix packages
will build correctly, and no definitions expected by Windows programs or from MS
compilers are available, so no Windows packages will build correctly.

The Cygwin C library libc is newlib not glibc so not a lot of GNU nor all Posix
interfaces are available.

Mingw includes sufficient compatible Windows definitions to allow Windows
interfaces to be built and run natively for interoperability.

As far as I know, all gcc compilers target gas DEC/AT&T assembler pseudo-ops and
instruction formats not MS or Intel pseudo-ops and/or instruction formats.

The full Windows definitions are proprietary and are only available if a MS
compiler is installed.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list