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: [email protected]
          Reporter: [email protected]

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.

--

Reply via email to