I am rewriting some old code which has an array of structs, each with an array member whose length is fixed at compile-time. The number of structs in the outer array is determined at compile-time to fit in a (typical) memory page. I would like to make the inner array variable at runtime, but keep the “outer array fits in a page” logic intact (and use sysconf(_SC_PAGESIZE) to get the page size precisely). So my structs have a flexible array member
struct foo_t
{
bar_t *bar;
float baz[];
};
I would like an array of these things, but of course that is not allowed. But all of these structs will have the flexible array member the same size (run-time determined), so can I have an “array” of them instead? That is, have a char * with enough space to fit n of them, do the offset calculations myself, and cast the pointer offsets to foo_t * and then access, modify, etc.
My target is C99, C11 at a push.