extern(C) symbol conflicts
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jan 29 05:43:28 PST 2015
On 1/28/15 2:49 AM, Walter Bright wrote:
> On 1/27/2015 11:22 PM, Jacob Carlborg wrote:
>> On 2015-01-27 21:31, Steven Schveighoffer wrote:
>>
>>> For instance, if one library tags it as pure, but another does not. I
>>> think an error in that case is warranted.
>>
>> Yeah. Do the compiler need to look at the parameters as well? Even if
>> you put
>> const or immutable, it won't make difference on the C side. But it
>> will probably
>> be confusing if one is declared const and another is not.
>>
>
> C does not have name mangling, so:
>
> extern(C) void foo(int);
> extern(C) void foo(char);
>
> will mangle to the same name, although D will regard them as different
> symbols. C++ treats extern"C" names the same way.
Hah! so this actually makes me more convinced we should do it differently:
cfile.c
#include <stdio.h>
void cfunction() {printf("hello\n");}
file1.d
module file1;
extern(C) void cfunction(int);
file2.d
module file2;
extern(C) void cfunction(const char *);
main.d
import file1;
import file2;
void main()
{
cfunction(1);
cfunction("1");
}
This works, and prints "hello" twice.
I really think D should consider extern(C) functions as not
overloadable, and universally binding (i.e. it's not an error to have 2
identical definitions in separate modules, and it is an error to have 2
different overloads of an extern(C) fucntion). Is there a good reason to
do it the current way besides "that's what C++ does"?
-Steve
More information about the Digitalmars-d
mailing list