I have the following simple lines of code:
#include <glib.h>
#include <stdio.h>
void my_func () {
GHashTable htbls[3]; /* ASSUME LINE NUMBER IS N */
/* Do something */
}
int main (int argc, char *argv[]) {
my_func ();
return 0;
}
But
$gcc `pkg-config --cflags --libs glib-2.0` ./main.c
gives the following error:
./main.c:N: error: array type has incomplete element type
I don’t understand why the element type is incomplete. GHashTable is completely specified in glib.h.
Thanks in advance for your help.
It presumably means that
GHashTableis not completely defined in the headers you include. That is, there is likely a line inglib.hor one of the files it includes that reads something like:The structure tag could be different without changing my argument. There must be something similar because otherwise you’d get a different message about
GHashTablenot being recognized as a type name:There is no extra information provided about the structure in
<glib.h>; you don’t need to know it to use it. The API for the hash table functions probably deal withGHashTable *values only, so you don’t need to know what’s inside, any more than you need to know what’s inside aFILE *to be able to use it in your code (though macroized functions such asgetchar()might need to know about the internals ofFILE *; maybe a better analogy isDIR *, but that’s a POSIX interface and not necessarily as well known).It means you will need to use:
You can have arrays of pointers to incomplete types without problem.