This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

declare variable of struct with flexible array member at compile time

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

Parents
  • 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.

Reply
  • 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.

Children