2 ms·
Even better, you can use [C99 Flexible array members][1], e.g. something like: struct KeyedEntry { struct Entry entry; char key[]; // flexible
by aloisklink 3y ago
Even better, you can use [C99 Flexible array members][1], e.g. something like:
struct KeyedEntry {
struct Entry entry;
char key[]; // flexible array member
};
It's not too much more useful when just using `char`, but for other data types, it's a bit cleaner, since it handles alignment/padding better.
[1]: https://en.wikipedia.org/wiki/Flexible_array_member https://en.wikipedia.org/wiki/Flexible_array_member, or https://beej.us/guide/bgc/html/split/structs-ii-more-fun-with-structs.html#flexible-array-members https://beej.us/guide/bgc/html/split/structs-ii-more-fun-wit...
_Edit_: Something like this might not be suitable for the author, since they did mention how they wanted each `struct` to have a fixed size.