Creating an array of C structs
Namespace
rswhite4 at googlemail.com
Mon Jan 27 01:34:02 PST 2014
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 [] ;)
More information about the Digitalmars-d-learn
mailing list