extern(C) symbol conflicts

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 27 10:13:36 PST 2015


On 1/27/15 5:57 AM, Walter Bright wrote:
> On 1/26/2015 11:06 AM, Steven Schveighoffer wrote:
>> Is there a good reason why we shouldn't allow the duplicate
>> declaration in
>> multiple modules? I understand for D symbols -- those are actually
>> different
>> symbols.
>
> D's interface to C and C++ does not adopt C and C++ semantics, in
> particular, it does not adopt C and C++ name lookup rules, function
> overloading rules, template instantiation rules, etc. This is on purpose
> to reduce the complexity of the language.

I never said anything about C++. I don't see how that is relevant. C has 
no overloading rules or template instantiation rules.

>
> As in C and C++, it is up to the D programmer to follow the One
> Definition Rule when interfacing with those languages. Declaring the
> same function in multiple modules is a bad idea.
>

The problem I see is that C bindings are easy to make. If I need to 
reference I function, I just declare it. If some other library writer 
needs the same function, he declares it. But now, if anyone wants to use 
both libraries, you have to pick one or the other, even though they are 
the same.

I understand the idea behind keeping the lookup rules consistent. But C 
lookup rules ARE simple.

I would say if two extern(C) declarations are identical (i.e. same 
parameter types, same attributes), they don't conflict. What does this 
break?

-Steve


More information about the Digitalmars-d mailing list