c - Syntax to set an array-of-structs element via initializer? -


i have following c code:

typedef struct {     int x,y; } point2d;  point2d data[5]; 

later in code (i.e. not during initialization of data), want set individual elements of data x/y values. two-statement-code simple:

point2d pt = {.x = a, .y = b}; data[3] = pt; 

but there way in c in single statement? neither of following ideas seems valid c99 code (for gcc 4.8.2):

data[3] = {.x = a, .y = b}; data[3] = point2d{.x = a, .y = b}; data[3] = point2d(a,b); //c++-like syntax 

use compound literal:

data[3] = ( point2d ){.x = a, .y = b}; 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -