Is there a way to do something like the array initialization braces method for a pointer array?
myStruct* array = malloc(4*sizeof(myStruct));
array = {a,b,c,d}; //like this
The reason I’m interested is because the aforementioned lines are much nicer to look at than:
myStruct* array = malloc(4*sizeof(myStruct));
array[0] = blah0;
array[1] = blah1;
array[2] = blah2;
...
array[n] = blahn;
The variables I’m initializing to are variables passed as function arguments so I’m unable to efficiently iterate through them to initialize the array…
I think you can do it with C99. The feature is called “compound literals”.
Or, for arrays: