I have declared a struct, and I try to pass an array of those structs (as well as a double array of doubles, and an integer) into a function. I get an "array type has incomplete element type" message from gcc when I compile it. What have I gotten wrong in how I pass the struct to the function?
typedef struct graph_node {
int X;
int Y;
int active;
} g_node;
void print_graph(g_node graph_node[], double weight[][], int nodes);
I have also tried struct g_node graph_node[], but I get the same thing.
It’s the array that’s causing trouble in:
The second and subsequent dimensions must be given:
Or you can just give a pointer to pointer:
However, although they look similar, those are very different internally.
If you’re using C99, you can use variably-qualified arrays. Quoting an example from the C99 standard (section §6.7.5.2 Array Declarators):
Question in comments
In your
main(), the variable should be:or something faintly similar; maybe
You should be able to pass that with code like this:
That compiles (to object code) cleanly with GCC 4.2 (i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)) and also with GCC 4.7.0 on Mac OS X 10.7.3 using the command line: