ImportC: On the issue of using a type from two different C files

TheGag96 thegag96 at gmail.com
Sat Aug 27 02:34:39 UTC 2022


I've been trying out ImportC with libgit2 lately, and it's 
honestly a bit like magic!! Kudos to Walter for his work so far - 
this has been really cool. However, you may have seen Adam's 
[blog 
post](http://dpldocs.info/this-week-in-d/Blog.Posted_2022_05_16.html#importc-and-module-namespaces) about the issue that D's module namespaces create, where a type imported from two different .c files aren't compatible with each other. There's a [Bugzilla issue](https://issues.dlang.org/show_bug.cgi?id=22674) about it too, which Walter initially closed as WONTFIX because it seemed like it needed too difficult a fix.

Zig advertises a similarly "magic" C importing feature. I made 
[an example](https://github.com/TheGag96/zigwithc) trying a 
similar scenario to what Adam described, and it seems we're 
actually in "good company":


```
<proj path>/src/main.zig:11:16: error: expected type 
'.media.<username>.4ea9c2fa-455c-480d-adbd-b533afd47647.home.<username>.Coding.Zig.zigwithc.zig-cache.o.8cf07da78935aad995196c635ddb6192.cimport.struct_tm', found '.media.<username>.4ea9c2fa-455c-480d-adbd-b533afd47647.home.<username>.Coding.Zig.zigwithc.zig-cache.o.46100012acc16f9e9848385e1fd2122e.cimport.struct_tm'
     clibB.doIt(thing);
                ^~~~~
<proj 
path>/zig-cache/o/46100012acc16f9e9848385e1fd2122e/cimport.zig:121:30: note: struct declared here
pub const struct_tm = extern struct {
                       ~~~~~~~^~~~~~
<proj 
path>/zig-cache/o/8cf07da78935aad995196c635ddb6192/cimport.zig:121:30: note: struct declared here
pub const struct_tm = extern struct {
                       ~~~~~~~^~~~~~
```

I'd like to know how they plan to solve this issue themselves... 
Maybe we can help each other out in this regard.

I asked Adam about it on the Discord, and his suggestion was:

> but there is a pretty easy solution to this in any case: make 
> everything from importC be an alias back into an 
> implicitly-created global namespace

What do you think? This at least seems like a sound idea.


More information about the Digitalmars-d mailing list