With this struct:
typedef struct MyStack {
size_t size; // current size of stack
size_t max; // max size of stack
Item* data[];
} MyStack;
How do I do a proper malloc
and then realloc
? For example, if I do:
MyStack* stack = malloc(sizeof(MyStack));
stack->data = malloc(size * sizeof(Item*));
// ... and later on...
stack->data = realloc(stack->data, new_stack_size);
I get the following errors:
error: invalid use of flexible array member
error: invalid use of flexible array member (one error for each item above)
What would be the proper way to do this then? Would this be simpler using Item** data
instead of Item data[]
?