Creating an array of C structs

Colin Grogan grogan.colin at gmail.com
Mon Jan 27 01:06:15 PST 2014


Why wont the following code compile?

import std.stdio;

void main()
{
     myStruct[] mystructs = {
         {1, 1.1f},
         {2, 2.2f}
     };
}

extern(C){
     struct myStruct{
         int x;
         float y;
     }
}

It fails with the (unhelpful imo) error message:
source/app.d(7): Error: a struct is not a valid initializer for a 
myStruct[]

The reason I need a C struct is because I'm interfacing to a C 
library that expects an array of myStructs.


More information about the Digitalmars-d-learn mailing list