C2 forum

General Category => Ideas => Topic started by: shiv on December 18, 2020, 04:39:20 PM

Title: Fat pointer syntax support for 1D array like structs
Post 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.
Title: Re: Fat pointer syntax support for 1D array like structs
Post by: lerno on December 27, 2020, 12:27:48 AM
Ok, so a sort of syntactic sugar?

Code: [Select]
// So these would be equal:
y = s->data[x];
y = (*s)[x];

Correct?
Title: Re: Fat pointer syntax support for 1D array like structs
Post by: shiv on December 30, 2020, 05:27:15 PM
Yes!