public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: Why is __unix__ defined, and not __WINDOWS__ ?
Date: Mon, 13 May 2019 05:40:00 -0000	[thread overview]
Message-ID: <72c5e82b-38f0-8701-93fe-5682176017b6@SystematicSw.ab.ca> (raw)
In-Reply-To: <dfd043fb-620a-81a1-1611-91a982fc96cd@agner.org>


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

  reply	other threads:[~2019-05-13  5:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-12 18:22 Agner Fog
2019-05-12 19:52 ` Houder
2019-05-12 19:54 ` Hans-Bernhard Bröker
2019-05-12 20:29   ` Lee
2019-05-13  4:12   ` Agner Fog
2019-05-13  5:40     ` Brian Inglis [this message]
2019-05-13 14:49       ` Agner Fog
2019-05-13 16:16         ` Yaakov Selkowitz
2019-05-13  7:56     ` Soegtrop, Michael
2019-05-12 20:33 ` Mike Gran via cygwin
2019-05-12 20:54   ` Houder
2019-05-13  4:40     ` Brian Inglis
2019-05-13 10:04       ` Houder
2019-05-12 22:00 ` Houder
2019-05-12 23:12   ` Houder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72c5e82b-38f0-8701-93fe-5682176017b6@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).