[Issue 24435] New: [ImportC] Compilation fails when casting to struct defined in separate file
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 11 02:44:55 UTC 2024
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 at puremagic.com
Reporter: lance at 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.
--
More information about the Digitalmars-d-bugs
mailing list