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

Dave P. dave287091 at gmail.com
Sat Aug 27 05:24:59 UTC 2022


On Saturday, 27 August 2022 at 03:07:25 UTC, Mike Parker wrote:
> On Saturday, 27 August 2022 at 02:34:39 UTC, TheGag96 wrote:
>
>
>>
>> What do you think?
>
> This has been discussed a couple of times in our Foundation 
> meetings. The most recent was in May. See Walter's section in 
> the sumamry:
>
> https://forum.dlang.org/thread/uhgndrcnekedjqtarnwl@forum.dlang.org
>
> Iain suggested the following:
>
>> ImportC symbols, rather than going into a module space, should 
>> go into a global ImportC module. Each imported C file or 
>> header file is then appended to that module.
>
> Martin disagreed, and proposed an alternative:
>
>> Martin said that one problem with that approach is that a D 
>> module would have access to symbols it didn't import. He 
>> suggested the ideal solution would be for each header to have 
>> its own module that doesn't change from one invocation of the 
>> compiler to the next.

IMO, the best solution is to implement some variation of C23’s 
rules for tag compatibility where identical types with identical 
tags are treated as equivalent. Importing into a global C 
namespace means you can’t use two C headers with conflicting 
definitions of a type. Ideally, using C from D should be better 
than using C from C and allow you to resolve this situation via 
the module system while still allowing you to mix compatible 
types between C modules.


More information about the Digitalmars-d mailing list