struct table
{
int size;
key_value *array[];
};
struct table *create_table(int size)
{
struct table *table = calloc(1, sizeof(struct table));
table->size = size;
return table;
}
void resize_table(struct table *table, int new_size)
{
struct table *new_table = create_table(new_size);
for(int i = 0; i < table->size; i++)
{
key_value *p = table->array[i]->next;
while(has_next(p))
{
insert(new_table, p->key, p->value);
p = p->next;
}
}
*table = *new_table;
}
I tried making the array only array[]
, this didn't work either. When I try to get rehashed values through new_table
, it works perfectly. But after assigning *table = *new_table
and accessing rehashed values through table
, it doesn't work. Why does assert(new_table->array[23]->key==23)
work, but not assert(table->array[23]->key==23)
? I have put table equal to new_table, shouldn't they be the same now?
What's weird is that the size
value has changed, but not the array.
When I try to change just the pointer:
table->array = new_table->array;
I get invalid use of flexible array member
, which I don't understand, aren't I just changing a pointer in the struct to a different adress, why does it even matter that it's an array?
Can I solve this by using alloc/realloc maybe?