This issue might be tough to be resolve, but is easy to demonstrate:
// s.c
#include <stdio.h>
// d.d
static import s;
static import core.stdc.stdio;
void main(){
auto f = s.fopen("/dev/null", "r");
assert(f);
core.stdc.stdio.fclose(f); // Error 1
core.stdc.stdio.fclose(cast(shared)f); // Error 2
}
d.d(8): Error: function `core.stdc.stdio.fclose(shared(__sFILE)* stream)` is not callable using argument types `(__sFILE*)`
d.d(8): cannot pass argument `f` of type `__sFILE*` to parameter `shared(__sFILE)* stream`
d.d(9): Error: function `core.stdc.stdio.fclose(shared(__sFILE)* stream)` is not callable using argument types `(shared(__sFILE*))`
d.d(9): cannot pass argument `cast(shared(__sFILE*))f` of type `shared(__sFILE*)` to parameter `shared(__sFILE)* stream`
Those error messages are unhelpful as well.
Comment #1 by destructionator — 2022-10-05T15:52:02Z
This one I actually don't think is a bug. This is the D module system working as designed for declarations in D. Yes, they are extern(C) definitions, but it is still D code so the D rules ought to apply.
Though if you had two different .c files that both #included the same thing, then I *would* call it a bug, since C isn't supposed to work that way.
Comment #2 by dave287091 — 2022-10-05T15:53:44Z
If this is working as intended, then the error messages need to be fixed as they currently are impossible to understand.
Comment #3 by destructionator — 2022-10-05T15:57:54Z
Yeah, in some cases the compiler will print the full name to explain it, it apparently needs to here too.
Comment #4 by bugzilla — 2022-10-09T05:47:48Z
What's happening is that s.c is declaring struct Sfile. core.stdc.stdio is also declaring a struct Sfile, but a *different* one. Declarations in D files are not merged with declarations from C files.
One possible solution is for core.stdc.stdio to declare Sfile using ImportC.
Comment #5 by robert.schadek — 2024-12-13T19:24:54Z