Author Topic: Fat pointer syntax support for 1D array like structs  (Read 16475 times)

shiv

  • Newbie
  • *
  • Posts: 12
    • View Profile
Fat pointer syntax support for 1D array like structs
« 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.
« Last Edit: December 18, 2020, 04:53:55 PM by shiv »

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Fat pointer syntax support for 1D array like structs
« Reply #1 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?

shiv

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Fat pointer syntax support for 1D array like structs
« Reply #2 on: December 30, 2020, 05:27:15 PM »
Yes!