www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22332] New: ImportC: declarations in imported C files


          Issue ID: 22332
           Summary: ImportC: declarations in imported C files conflict
                    with D declarations.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

When a D file imports a preprocessed c file, there are likely going to be
symbols declared in both D and in C when using c standard headers. For example:

// stdio.i
int printf(const char * restrict, ...) __attribute__((__format__ (__printf__,
1, 2)));

// hello.d
import stdio;
import core.stdc.stdio;

void main(){
    printf("Hello world\n”); 

Compiling hello.d results in the following error:

hello.d(5): Error: function `core.stdc.stdio.printf` at
.../core/stdc/stdio.d/stdio.d(1274) conflicts with function `stdio.printf` at

As the probability of such a conflict in a project is very high, these
conflicts need to be resolved somehow.

Sep 23 2021