dmd
dmd copied to clipboard
ImportC: typedef function pointer calling convention changes if C file compiled.
This was reduced from code that uses <windows.h>
// z.c
typedef void (__stdcall* proc)(void);
struct Foo {
proc p;
};
// y.d
import z;
extern(C) void c();
extern(Windows) void w();
void main(){
Foo f;
pragma(msg, typeof(f.p).stringof);
f.p = &c;
f.p = &w;
}
A command line like dmd y.d prints extern (C) void function() and trying to assign &w fails.
A command line like dmd y.d z.c prints extern (Windows) void function() and trying to assign &c fails.
I think I found the root cause, we're getting some unanticipated aliasing of types that the semantic routines aren't setup to handle due to the way C typedefs are getting resolved. Because of this, things can get run in a different order or just skipped.
I think I've got a fix cooking.