[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 Jacob Carlborg changed: What|Removed |Added CC||d...@me.com --- Comment #1 from Jacob Carlborg --- I don't think it's the mangling that is wrong. Rather it's the declaration of the struct. Not sure why it's called "stat_t" in the D version when it's called "stat" in the C headers. --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 Vladimir Panteleev changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #2 from Vladimir Panteleev --- (In reply to Jacob Carlborg from comment #1) > Not sure why it's called "stat_t" in the D version when it's > called "stat" in the C headers. It's because in C, "stat" is both the name of a struct and a function. This is not a problem for C because structs in C have their own namespace (unless you typedef them), but there is no equivalent in D. There are some workarounds available: - You can use extern(C) to link the D declaration with the C definition. As argument types are not mangled with C linkage, type name mismatches will not result in a link error. - You can use pragma(mangle) on the D side to directly override a function's mangled name; - Finally, on the D side you could declare the function as: struct stat; void myFunc(stat*){} then cast the stat_t* to stat* when invoking the function. As this is not a bug in D and simple workarounds exist, I'll close this, but feel free to reopen if you can present actionable ideas for improving the situation. --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 Vladimir Panteleev changed: What|Removed |Added Keywords||C++ Hardware|x86_64 |All --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 --- Comment #3 from Jacob Carlborg --- Is it possible to use pragman(mangle) on a struct? --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 --- Comment #4 from Vladimir Panteleev --- It's easy enough to test! $ cat test.d pragma(mangle, "CeciNestPasUnS") struct S { } extern(C++) void fun(S* s); pragma(msg, fun.mangleof); $ dmd -o- test.d _Z3funP1S Looks like pragma(mangle) has no effect on structs so far. --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 --- Comment #5 from Jacob Carlborg --- (In reply to Vladimir Panteleev from comment #4) > It's easy enough to test! > > $ cat test.d > pragma(mangle, "CeciNestPasUnS") > struct S { } > > extern(C++) void fun(S* s); > > pragma(msg, fun.mangleof); > > $ dmd -o- test.d > _Z3funP1S > > Looks like pragma(mangle) has no effect on structs so far. I didn't really expect it to work. Perhaps a worthwhile feature? --
[Issue 16650] Wrong mangling for extern(C++) with posix stat_t
https://issues.dlang.org/show_bug.cgi?id=16650 --- Comment #6 from Vladimir Panteleev --- (In reply to Jacob Carlborg from comment #5) > I didn't really expect it to work. Perhaps a worthwhile feature? Perhaps! Feel free to file an enhancement request. --