The "incomplete type" error but header file is included

C

Charles Packer

In the code example below, why does the reference to
gdk_pixbuf_new_from_file in main compile okay, but
in subr2 gives the error "dereferencing pointer to
incomplete type"? A search through this newsgroup
suggests that the error arises when the proper
header files are missing, but when the header file I've
got is sufficient to compile one instance of the
call, but not the other, I don't know where to turn
next.

#include <gtk/gtk.h>
subr2 (GdkPixbuf *YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);
}
main(int argc, char *argv[]){
GdkPixbuf *XX = gdk_pixbuf_new_from_file("somefile", NULL);
}

The reason I'm coding this way is convenience (in code I'm
writing only for myself, incidentally). It seems to be a way
to set multiple variables with a single function call, as
in setimgpars(&nbands, &width, &height). Has worked fine
for integers...
 
R

Richard

Charles Packer said:
In the code example below, why does the reference to
gdk_pixbuf_new_from_file in main compile okay, but
in subr2 gives the error "dereferencing pointer to
incomplete type"? A search through this newsgroup
suggests that the error arises when the proper
header files are missing, but when the header file I've
got is sufficient to compile one instance of the
call, but not the other, I don't know where to turn
next.

#include <gtk/gtk.h>
subr2 (GdkPixbuf *YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);
}
main(int argc, char *argv[]){
GdkPixbuf *XX = gdk_pixbuf_new_from_file("somefile", NULL);
}

quick glance says

in subr2 you are storing the return from gdk call into the memory
location pointed to by YY.

in main you are assigning the return value from gdk call to a pointer to
a PixBuf


GdkPixbuf XX;
GdkPixBuff *YY;
YY=&XX;
*YY = gdk_pixbuf_new_from_file("somefile", NULL);

might be better I think
 
M

MQ

In the code example below, why does the reference to
gdk_pixbuf_new_from_file in main compile okay, but
in subr2 gives the error "dereferencing pointer to
incomplete type"? A search through this newsgroup
suggests that the error arises when the proper
header files are missing, but when the header file I've
got is sufficient to compile one instance of the
call, but not the other, I don't know where to turn
next.

#include <gtk/gtk.h>
subr2 (GdkPixbuf *YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);}

It should be:

subr2 (GdkPixbuf **YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);}

While I know nothing of GDK, this is most likely the problem. In
main, you are initializing a pointer to a GdkPixbuf, whereas in subr2
you are trying to initialize a GdkPixbuf, not a pointer to it. When
calling subr2, be sure to do it this way

GdkPixbuf *a;
subr2(&a);

Regards,
B.
 
M

Martin Ambuhl

Charles said:
In the code example below, why does the reference to
gdk_pixbuf_new_from_file in main compile okay, but
in subr2 gives the error "dereferencing pointer to
incomplete type"? A search through this newsgroup
suggests that the error arises when the proper
header files are missing, but when the header file I've
got is sufficient to compile one instance of the
call, but not the other, I don't know where to turn
next.

#include <gtk/gtk.h>
subr2 (GdkPixbuf *YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);
}
main(int argc, char *argv[]){
GdkPixbuf *XX = gdk_pixbuf_new_from_file("somefile", NULL);
}

It appears, from your use in main, that gdk_pixbuf_new_from_file returns
a pointer-to-GdkPixbuf. However, in subr2 you assign it to *YY. Since
YY is a pointer-to-GdkPixbuf, *YY is not, but is a GdkPixbuf. That
means (1) you need a visible typedef of GdkPixbuf, while you did not
need one for pointer-to-GdkPixbuf, and (2) that subr2 is almost
certainly wrong and should have a prototype of
void subr2 (GdkPixbuf **YY);
Note two things:
1) That YY is now a pointer-to-pointer-to-GdkPixbuf, and so *YY is now a
pointer-to-GdkPixbuf
2) subr2 without a return type under the old standard implicitly
returned an int, and you did not do so. Failing to return a value from
a function promising to do so is a mistake. Worse, implicit int is now
removed from the language and you need to explicitly declare the return
type for functions. 'void' seems the right one, since you don't return
a value.
 
M

MQ

Charles Packer said:
In the code example below, why does the reference to
gdk_pixbuf_new_from_file in main compile okay, but
in subr2 gives the error "dereferencing pointer to
incomplete type"? A search through this newsgroup
suggests that the error arises when the proper
header files are missing, but when the header file I've
got is sufficient to compile one instance of the
call, but not the other, I don't know where to turn
next.
#include <gtk/gtk.h>
subr2 (GdkPixbuf *YY) {
*YY = gdk_pixbuf_new_from_file("somefile", NULL);
}
main(int argc, char *argv[]){
GdkPixbuf *XX = gdk_pixbuf_new_from_file("somefile", NULL);
}

quick glance says

in subr2 you are storing the return from gdk call into the memory
location pointed to by YY.

in main you are assigning the return value from gdk call to a pointer to
a PixBuf

GdkPixbuf XX;
GdkPixBuff *YY;
YY=&XX;
*YY = gdk_pixbuf_new_from_file("somefile", NULL);

might be better I think

You've made exactly the same mistake as the OP has. You are still
assigning to a GdkPixbuf.

Regards,
B.
 
C

Charles Packer

need one for pointer-to-GdkPixbuf, and (2) that subr2 is almost
certainly wrong and should have a prototype of
void subr2 (GdkPixbuf **YY);

That works. It's obvious now...and maybe if I
code it GdkPixbuf *(*YY) it will help me to
remember what's going on there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top