4 ms·
No structs, just an array that accomplishes the same thing, without field names or other niceties. Enjoy the pleasure of not using a struct when you inevitably
by t-3 4mo ago
No structs, just an array that accomplishes the same thing, without field names or other niceties. Enjoy the pleasure of not using a struct when you inevitably add/reduce/reorder fields later.
- hibberl7 4mo ago[dead]
- sparkie 4mo agoThe reason the struct is avoided here is so the array can be typed to its element type (rather than casting to and from `void*`). With a struct we would need one struct for each element type - at least prior to C23 which provides a better approach where we can declare the same struct multiple times in a translation unit. #define Array(T) struct array_##T { size_t len; T *elems; } We can use `Array(int)` in multiple places in the same TU - but in C11 or earlier, this is an error.
- alurm 4mo agoGood point! Added `vec_ptr[vec]` and `vec_len[vec]` helpers to mitigate this somewhat.