www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Clarity about extern(Windows)/extern(System)

reply Mike Parker <aldacron gmail.com> writes:
For years now, I've been under the impression that the 
distinction between extern(Windows) and extern(System) actually 
mattered. I recall extern(System) was first added to the language 
to resolve this situation for C bindings:

version(Windows) extern(Windows):
else extern(C):

Which, or course, does not work. Yet, it's now been pointed out 
to me [1] that the documentation says the following [2]:

The Windows convention is distinct from the C convention only on 
Win32 platforms, where it is equivalent to the stdcall convention.

This implies that extern(Windows) and extern(System) behave the 
same way. My limited testing on a 64-bit Linux VM shows no 
problems when binding a C function as extern(C) or 
extern(Windows), and the disassembly looks the same.


[1]: https://github.com/Extrawurst/DerelictFmod/pull/3
[2]: https://dlang.org/spec/attribute.html#linkage
Dec 17 2017
parent reply Kagamin <spam here.lot> writes:
On Sunday, 17 December 2017 at 13:36:15 UTC, Mike Parker wrote:
 My limited testing on a 64-bit Linux VM shows no problems when 
 binding a C function as extern(C) or extern(Windows), and the 
 disassembly looks the same.
64-bit ABI fixed calling convention proliferation, only one cc is used there.
Dec 18 2017
parent reply Mike Parker <aldacron gmail.com> writes:
On Monday, 18 December 2017 at 10:52:22 UTC, Kagamin wrote:
 On Sunday, 17 December 2017 at 13:36:15 UTC, Mike Parker wrote:
 My limited testing on a 64-bit Linux VM shows no problems when 
 binding a C function as extern(C) or extern(Windows), and the 
 disassembly looks the same.
64-bit ABI fixed calling convention proliferation, only one cc is used there.
What about extern(Windows) on 32-bit Posix?
Dec 18 2017
next sibling parent reply Kagamin <spam here.lot> writes:
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html#index-functions-that-pop-the-argume
t-stack-on-x86-32-3 looks like gcc doesn't see it as OS dependent.
Dec 18 2017
parent Mike Parker <aldacron gmail.com> writes:
On Monday, 18 December 2017 at 14:31:38 UTC, Kagamin wrote:
 https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html#index-functions-that-pop-the-argume
t-stack-on-x86-32-3 looks like gcc doesn't see it as OS dependent.
Thanks. I was playing around on asm.dlang.org and found there's a definite difference in 32-bit output.
Dec 18 2017
prev sibling parent Kagamin <spam here.lot> writes:
 From https://gcc.godbolt.org/

__attribute__((stdcall))
int square(int num) {
     return num * num;
}

_Z6squarei:
   push ebp
   mov ebp, esp
   mov eax, DWORD PTR [ebp+8]
   imul eax, DWORD PTR [ebp+8]
   pop ebp
   ret 4
Dec 18 2017