[Issue 23402] New: importc function definitions from includes can cause D name conflicts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 10 13:07:17 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23402
Issue ID: 23402
Summary: importc function definitions from includes can cause D
name conflicts
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: destructionator at gmail.com
Suppose you have a.c that #include<stdio.h> and b.c that also includes it.
Then the D file imports both a and b. Now functions like printf get a name
conflict.
This is expected in D, since different modules have their own namespaces. But
in C, it is common for different headers to include different things. An
include guard keeps it out there, but in D this doesn't work so well.
I suggest putting the importC symbols in a magic module, then public aliasing
them/selectively importing them into the D module being imported with the
include. Then they refer to the same C namespace while keeping the D namespace
hygienic and avoids spurious conflicts.
--
More information about the Digitalmars-d-bugs
mailing list