C2 forum
General Category => Ideas => Topic started by: shiv on December 18, 2020, 04:39:20 PM
-
It would be nice to allow the following type of syntax:
struct S {
int len;
f32 data[];
};
struct S *s = malloc( sizeof( struct S ) + 100 * sizeof( f32 ) );
s->len = 100;
(*s)[0] = (*s)[1] + (*s)[2];
So if a struct ends with a variable length array (or just a pointer type) then the array access syntax using [] is honored.
-
Ok, so a sort of syntactic sugar?
// So these would be equal:
y = s->data[x];
y = (*s)[x];
Correct?
-
Yes!