« Last post by shiv on December 18, 2020, 05:18:35 PM »
Gnu C extension allows: void * foo (int n) { struct S { int data[n]; }; int (*s)[n] = malloc( sizeof (int[n]) ); ... } which is very convenient. It would be even better to allow support for the following: struct S { int n; f32 (*data)[.n]; // the ".n" refers to the internal field }
It would be even more awesome to allow wrapping multi-dimensional arrays: struct S2 { int m; int n; f32 (*d)[.m][.n]; } struct S2 a2; a2.m = 100; a2.n = 50; a2.d = malloc( sizeof( f32[a2.m][a2.n] ); (*a2.d)[0][0] = (*a2.d)[1][1] + (*a2.d)[2][3];
If we then combine with my previous suggestion of allowing array access syntax on "fat pointers" we could do: (*a2)[0][0] = (*a2)[1][1] + (*a2)[2][3];
« Last post by lerno on December 17, 2020, 02:54:38 AM »
An interesting feature in Odin is that of "distinct" types. That is, it acts like you actually created a completely new type, not a typedef alias. That way you can for example have a "UserId" type which is an int underneath but typechecks as if it was another type.