static init c struct with array filed

Mike Parker aldacron at
Thu Mar 17 00:16:39 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).

Any time you see a '[]' in C, the equivalent declaration in D has 
to be a pointer. Like Ali said, D's arrays are a pointer and 
length pair, so declaring the declaration of the `arr` member 
will not match the declaration on the C side.

Since you say you can't change the declaration on the C side, 
user1234's answer is the direction you want to go (though you 
don't need the `extern(C)` on the structs).

More information about the Digitalmars-d-learn mailing list