[SPEC/DMD] Bug (?): extern( C ) function pointers (D1 and D2)
David Nadlinger
see at klickverbot.at
Thu Dec 30 13:28:22 PST 2010
As easily verified e.g. by compiling
---
extern(C) void foo() {}
pragma( msg, typeof( &foo ) );
---,
function pointers types include the linkage type (the code above prints
»void C function()«).
However, there is no way to specify the linkage type e.g. in the
signature of a function accepting a delegate, i.e.:
---
extern(C) void foo() {}
void bar( void function() func ) {} // How to correctly specify the full
parameter type here?
void main() {
bar( &foo );
}
---
This problem is currently somewhat hidden by the fact that DMD simply
ignores the linkage when doing type checking. But e.g. LDC does strict
type checking (probably because it needs to reflect the pointer types in
the LLVM IR, but that's just guessing) today, and it will hopefully be
added to DMD at some point.
Note: Simply adding »extern( C )« to the type specification does not
work, but: At the first glance, I couldn't even find any section in the
language spec for both D1 and D2 mentioning linkage annotations for
function pointers. Has this part simply not been spec'd yet?
In any case, this currently breaks passing of function pointers to C
functions resp. their SWIG-generated wrappers with LDC, as I could find
no easy way to work around it – creating an alias for the function
pointer type before might work, as extern( C ) seems to be accepted
there, but this is a major annoyance if you are automatically generating
code.
David
More information about the Digitalmars-d
mailing list