Linkage problem with D interface files used in place of C headers when structs contain doubles. #23814
Replies: 3 comments 1 reply
|
Reduced further: struct b_real {
double val;
}main.d import di;
int main() { return 0; }
b_real* alcb_real(double x) {
return new b_real;
}I notice that the results are identical if the di.di file is renamed to di.d and omitted from the compiler invocation (ie |
|
OK, so is it a bug? Any opinions? |
They are used only for semantic analysis, not code generation.
Better to always name the D modules |
Uh oh!
There was an error while loading. Please reload this page.
I ran into a linkage problem using a big D interface file to work with a big C project. In a nutshell, if a struct containing a double is in a C compatible D interface file then allocating that struct with
newin a D module that imports the D interface in that file causes a linkage error, seeking xtoHash and xopEquals for that struct. (I'm using gdc, but presumably the problem is over here too.)Provided
=voidis attached to every struct member in the interface file, it can be imported without difficulty into D modules without ever being compiled, excepting only so far as I know when a double is a struct member.I wrote a toy version of the problem, apart from
=voidsee here for actual details of the above.https://forum.dlang.org/post/crrjqrskndpvptbtpetf@forum.dlang.org
It seems a D interface file cannot be used in this simplistic way to give types in a C project as a replacement for the header files in that project which cannot be used in D source.
Also, if the D interface file itself is compiled and the resulting object included in the project's build, it does not provide the necessary xtoHash and xopEquals to resolve the linkage problem. (Renaming as a D source file by changing the extension from .di to .d resolves the problem, so there is an operational solution.)
Is it me, or is this linkage problem a bug! Since equality of doubles isn't just bitwise equality, hashing or comparing (for equality) structs containing a double is subtle, so plainly for use in D those special methods are necessary. The linkage error can be avoided if the struct containing a double is allocated with say GC.calloc, but presumably this just defers the problem.
A D interface file is for interface to compiled D code it seems, where xtoHash and xopEquals would be present for such a struct. It's not really able to be a C interface file for D, unless this issue with doubles can be solved.
All reactions