Creating named tempfiles

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 4 01:44:39 PST 2015


On Wednesday, February 04, 2015 09:33:22 ketmar via Digitalmars-d wrote:
> On Wed, 04 Feb 2015 01:13:18 -0800, Jonathan M Davis via Digitalmars-d
> wrote:
>
> >> for the most time `extern(Windows)` is using only for winapi calls. and
> >> `wsopen` is a library call, so it's likely an `extern(C)`.
> >
> > Well, unfortunately, a C function is a C function to me. I know that
> > different calling conventions exist in Windows, but I have no idea why,
> > what the difference is, or what they affect. AFAIK, it's not an issue
> > that exists on POSIX systems. I really should study up on it.
>
> it's mostly historical artifacts. and it's too late to change that. most
> of the time it's used to make your program crash in most unexpected ways.
>
> first windows was written in pascal, so it has pascal calling convention
> (left-to-right order, callee cleans the stack). i don't know why, but
> when they go to 32-bit version, they start using stdcall calling
> convention (right-to-left order, yet callee still cleans the stack). that
> is what `extern(Windows)` in D means. and most of other libraries written
> in C, and they using cdecl convetion (right-to-left order, caller cleans
> the stack). lovely things, aren't they?
>
> so you have to triple-check your declarations when using windows. 'cause
> besides name mangling, you can accidentally mark some stdcall function as
> cdecl, and your program will work... for some time. but with bad stack
> pointer, which will lead to some mystical bugs later.

Just one more reason to hate Windows, I guess.

- Jonathan M Davis



More information about the Digitalmars-d mailing list