Bug 6132 – extern (C) Silently Ignored Within D Classes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2011-06-09T09:17:03Z
Last change time
2024-12-13T17:55:28Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Braxton Sherouse
See also
http://d.puremagic.com/issues/show_bug.cgi?id=1470, http://d.puremagic.com/issues/show_bug.cgi?id=4399, https://issues.dlang.org/show_bug.cgi?id=15712, https://issues.dlang.org/show_bug.cgi?id=15843
Moved to GitHub: dmd#18346 →

Comments

Comment #0 by sherouse — 2011-06-09T09:17:03Z
Overview: I'm running DMD32 v2.053 on Mac OS X 10.6.7 and found the following inconsistency in name mangling: ==== extern(C) int clock(); // is mangled to _clock class Sprocket { extern(C) int clock(); // is mangled to __D4test8Sprocket5clockMUZi: } ==== Expected Results: The compiler should either: 1) mangle the declaration according to the C conventions by cause of the "extern (C)", or: 2) emit a compilation error because C doesn't have classes. Actual Results: The declaration is silently compiled according to the D conventions. Additional Information: While either solution would be welcomed, I'm working in context where solution 1 would save a lot of effort; I'm generating language/library bindings at compile time through the use of template metaprogramming. The code builds a (more robust) interface in D, and is just using the extern (C) to declare C functions that will later be linked in from other libraries. Maybe it would be possible for the compiler to allow this syntax when there is no function body, but fail when there is?? Many thanks! -braxton
Comment #1 by sherouse — 2011-06-25T19:41:29Z
Another peculiarity to add: class Sprocket { extern (C) static int clock(); // not added to the symbol table! }
Comment #2 by code — 2011-11-26T08:54:58Z
The latter happens when you don't reference that function.
Comment #3 by code — 2011-11-26T11:40:56Z
*** Issue 7005 has been marked as a duplicate of this issue. ***
Comment #4 by code — 2011-11-29T08:59:07Z
Actually one needs to note, that extern(C) is not ignored for the calling convention. It is only ignored for the mangling and the hidden this argument. It even results in different delegate types for extern(C) and extern(D) methods. So on a struct method extern(C) behaves as __cdecl but not as extern(C). A clean cut would be to disallow extern(C/Pascal/Windows) on structure level except for static methods. If there were a real need for declaring the calling convention than that should become a different construct.
Comment #5 by andrei — 2016-10-14T16:54:36Z
@Martin so is there anything to fix for this?
Comment #6 by dfj1esp02 — 2016-10-18T08:29:32Z
(In reply to Martin Nowak from comment #4) > A clean cut would be to disallow extern(C/Pascal/Windows) on structure level > except for static methods. extern(Windows) methods are needed for COM.
Comment #7 by robert.schadek — 2024-12-13T17:55:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18346 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB