Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > The "incomplete type" error but header file is included

Reply
Thread Tools

The "incomplete type" error but header file is included

 
 
Charles Packer
Guest
Posts: n/a
 
      10-09-2007
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...

--
Charles Packer
http://cpacker.org/whatnews
mailboxATcpacker.org

 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      10-09-2007
Charles Packer <(E-Mail Removed)> writes:

> 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
 
Reply With Quote
 
 
 
 
MQ
Guest
Posts: n/a
 
      10-09-2007
On Oct 9, 9:41 pm, Charles Packer <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      10-09-2007
Charles Packer wrote:
> 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.
 
Reply With Quote
 
MQ
Guest
Posts: n/a
 
      10-09-2007
On Oct 9, 9:57 pm, Richard <(E-Mail Removed)> wrote:
> Charles Packer <(E-Mail Removed)> writes:
> > 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.

 
Reply With Quote
 
Charles Packer
Guest
Posts: n/a
 
      10-10-2007
On Oct 9, 3:33 pm, Martin Ambuhl <(E-Mail Removed)> wrote:
> 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.

--
Charles Packer
http://cpacker.org/whatnews
mailboxATcpacker.org



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Header file included more than once? Pietro Cerutti C Programming 4 08-09-2007 07:47 PM
why does the complier complain undeclare identifier even though i have included the header file? thinktwice C++ 3 02-10-2006 12:57 PM
Header files included in header files John Smith C Programming 18 07-24-2004 04:55 AM
Inline script works - but fails when included from .js file - why? Randell D. Javascript 7 10-26-2003 07:04 PM



Advertisments