static init c struct with array filed
user1234
user1234 at 12.de
Wed Mar 16 11:27:20 UTC 2022
On Wednesday, 16 March 2022 at 07:27:06 UTC, test wrote:
> ```c
> struct Test {
> int32_t a;
> }
> struct Test2 {
> int32_t a;
> Test arr[];
> }
> ```
>
> I need static const init Test2, then pass it to c library
> late(third library, can not change the type def).
>
>
> I am not sure how to do it in D.
```d
extern(C) struct Test {
int a;
}
extern(C) struct Test2 {
int a;
Test* arr;
}
static const Test2 t2 = Test2(2, null);
void main(){
to_c_library(&t2);
to_c_library(new Test2(2, null));
Test2 local;
to_c_library(&local);
}
```
assuming the c library takes by reference
More information about the Digitalmars-d-learn
mailing list