A
Andrea Taverna
Hi folks.
I wrote the following piece of code
struct ht {
size_t count;
size_t size;
float load_treshold;
unsigned long (*hashf) (hash_item*);
boolean (*testf) (hash_item*, hash_item*);
unsigned long (*probef) (long, hash_item*, void*);
unsigned long (*newsizef) (void*);
slot* data[];
};
and compiled it with C99 standard.
I don't know the details of such standard but, apparently, the compiler thinks
that I'm trying to define a struct with a "flexible array data", with the result
that the following
struct ht foo;
foo->data = calloc(sizeof(slot)*some_size));
gets rejected as "invalid use of flexible array member".
As far as I understand, I should change code like that one into
struct ht* foo;
foo = malloc((sizeof(slot)*some_size)+ <size of other fields>);
Is it correct?
What should I do if I want to use a flexible array *without* "struct hacks"
*nor* C99 rules?
Should I switch to another standard?
TIA,
Andrea
I wrote the following piece of code
struct ht {
size_t count;
size_t size;
float load_treshold;
unsigned long (*hashf) (hash_item*);
boolean (*testf) (hash_item*, hash_item*);
unsigned long (*probef) (long, hash_item*, void*);
unsigned long (*newsizef) (void*);
slot* data[];
};
and compiled it with C99 standard.
I don't know the details of such standard but, apparently, the compiler thinks
that I'm trying to define a struct with a "flexible array data", with the result
that the following
struct ht foo;
foo->data = calloc(sizeof(slot)*some_size));
gets rejected as "invalid use of flexible array member".
As far as I understand, I should change code like that one into
struct ht* foo;
foo = malloc((sizeof(slot)*some_size)+ <size of other fields>);
Is it correct?
What should I do if I want to use a flexible array *without* "struct hacks"
*nor* C99 rules?
Should I switch to another standard?
TIA,
Andrea