On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote:
On Monday, 27 January 2014 at 09:06:17 UTC, Colin Grogan wrote:
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.

myStruct[] mystructs = [
    {1, 1.1f},
    {2, 2.2f}
];

Arrays are enclosed in [] ;)

I'm an idiot.
Can I delete this thread to save further embarrassment? :)

Reply via email to