Bug 20993 – spec claims extern(C) and extern(D) function are identical

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2020-06-29T20:02:28Z
Last change time
2022-02-17T03:21:54Z
Keywords
spec
Assigned to
No Owner
Creator
Steven Schveighoffer

Comments

Comment #0 by schveiguy — 2020-06-29T20:02:28Z
The spec on the ABI claims that "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system." https://dlang.org/spec/abi.html#function_calling_conventions On MacOS, however, the calling convention of even 2 int parameters is different: --- foo.c #include <stdio.h> void foo(int a, int b) { printf("a=%d b=%d\n", a, b); } --- main.d pragma(mangle, "foo") extern (D) void foo_extern_d(int, int); pragma(mangle, "foo") extern (C) void foo_extern_c(int, int); void main() { foo_extern_d(1, 2); foo_extern_c(1, 2); } --- gcc -c foo.c dmd main.d foo.o ./main a=2 b=1 a=1 b=2 Clearly, the arguments are passed in a different order depending on whether the function is extern(C) or extern(D). Either the spec should be updated, or the compiler should be modified to match the spec.
Comment #1 by duser — 2022-02-17T03:21:54Z
*** This issue has been marked as a duplicate of issue 20204 ***