www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24435] New: [ImportC] Compilation fails when casting to

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

          Issue ID: 24435
           Summary: [ImportC] Compilation fails when casting to struct
                    defined in separate file
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lance lancebachmeier.com

structdef.c:

typedef struct {
        int a;
        double b;
} foo;

test.c:

#include <stdio.h>
#include <stdlib.h>

__import structdef;

int main() {
        int * x = (int *) malloc(2*sizeof(int));
        x[0] = 1;
        x[1] = 2;
        printf("%d\n", x[0]);
        printf("%d\n", x[1]);

        // Fails to compile because it's imported
        foo * y = (foo *) malloc(sizeof(foo));
}

Compile with DMD 2.108.0-beta.1:

test.c(13): Error: expression expected, not `)`
test.c(13): Error: found `malloc` when expecting `)`

If the definition of foo is moved into test.c, it compiles and runs. The error
only occurs when foo is defined in a separate file.

--
Mar 10