Comment #0 by peter.alexander.au — 2011-12-03T15:27:20Z
If you have a D symbol that mangles to the same name as a C symbol you receive no warnings or errors and your program silently exhibits incorrect behaviour:
import std.stdio;
extern(C) void D4test3fooFZv() { writeln(1); }
void foo() { writeln(2); }
void main()
{
D4test3fooFZv();
foo();
}
For me, this outputs:
1
1
DMD should probably give an error or at least a warning when two symbols conflict like this.
Comment #1 by peter.alexander.au — 2011-12-03T15:39:49Z
If it wasn't obvious from the code given above, the module must be named 'test'
Comment #2 by andrej.mitrovich — 2012-10-21T14:53:49Z
How come you're not getting linker errors? I am on win32:
Error 1: Previous Definition Different : _D4test3fooFZv
Comment #3 by peter.alexander.au — 2012-10-21T15:40:22Z
(In reply to comment #2)
> How come you're not getting linker errors? I am on win32:
>
> Error 1: Previous Definition Different : _D4test3fooFZv
Different linker on Windows vs. OSX.
Comment #4 by dfj1esp02 — 2017-07-10T16:22:46Z
This can be reliably diagnosed only by the linker, since duplicate symbols can be buried in libraries or come from different object files.
Comment #5 by dlang-bugzilla — 2017-07-10T22:21:02Z
(In reply to anonymous4 from comment #4)
> This can be reliably diagnosed only by the linker, since duplicate symbols
> can be buried in libraries or come from different object files.
The compiler probably shouldn't be passing garbage to the linker if it can help it, though.
Comment #6 by ibuclaw — 2023-01-15T14:31:23Z
This is an error when compiling with gdc (even if it could be more clearer as to why it conflicts). This error needs to be there as the assembler would otherwise complain about duplicate symbols.
---
$ gdc test.d
test.d:4:6: error: function ‘test.foo’ at test.d:4:6 conflicts with function ‘test._D4test3fooFZv’ at test.d:3:16
4 | void foo() { writeln(2); }
| ^
---
Comment #7 by robert.schadek — 2024-12-13T17:57:08Z