-
Memory Allocation issues
I'm trying to allocate memory for an array of pointers to structures with:
Code:
struct onode *onodeArray[size] = (struct onode**)calloc(size,sizeof(struct onode*));
size is a parameter of the function this command is in, and it's simple the size (number of rows) of the array. My problem is that I'm getting this message when I try to compile my code: error: variable-sized object may not be initialized
-
> struct onode *onodeArray[size]
Use
struct onode **onodeArray
-
In addition to Salem's advice, if you want the code to compile then turn the "(struct onode **)" type conversion into "(struct onode *)". i.e. you have one two many asterixes.
In C, it is best to remove the type conversion completely, as it is not required. If you need it then either you have forgotten to #include <stdlib.h> or you are using a C++ compiler (which does require the type conversion) OR both.