Hello everybody,
is it possible to use a struct with flexible array members and declare a variable of it at compile time?
e.g.:
struct sFoo { uint32_t const num_Elements; uint8_t baz[]; } #define DECLAREFOO (name, nElements) \ struct sFoo name = { (nElements), ..?}
what I am using is the following:
struct sFoo { uint32_t const num_Elements; uint8_t * const baz; } #define DECLAREFOO (name, nElements) \ uint8_t name##_container[ (sizePerElement) * (numElements)]; \ struct sFoo name = { (nElements), & name##_container[0]}
Can anyone think of a smarter way to do this without the container or malloc?
Thanks for your replies Alexander
Many people neglect to fill in the "Architecture" field in their posts. Yours is one of those, and that makes it impossible to answer your question, because whether or not that an alternative is feasible depends entirely on which compiler you have.
They can't neglect it - because the forum insists that one make a selection. Therefore they must have deliberately selected "Non-Specific (Generic)"...
Andrew is right, i chose generic as I don't think this is an architecture or tool based problem. In fact, for reusability, I am hoping to get an all-purpose answer that I cannot only use within one specific architecture...