Creating named tempfiles

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 4 01:33:22 PST 2015


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150204/3dc7791f/attachment.sig>


More information about the Digitalmars-d mailing list