www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22886] New: ImportC: forward declaration of struct in a

https://issues.dlang.org/show_bug.cgi?id=22886

          Issue ID: 22886
           Summary: ImportC: forward declaration of struct in a function
                    prototype leads to "redeclaration with different type"
                    error.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

The following C code fails to compile:

// test.c
struct config *Configlist_add(int);
struct config *Configlist_add(int x){ // Error: function `test.Configlist_add`
redeclaration with different type  
  return 0;
}

struct config {
  int dot;
};


Strangely, if the function takes no arguments there is no error. If you forward
declare the struct at the top of the file, there is no error.

--
Mar 17 2022