The "incomplete type" error but header file is included

Discussion in 'C Programming' started by Charles Packer, Oct 9, 2007.

  1. 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
    Charles Packer, Oct 9, 2007
    #1
    1. Advertising

  2. Charles Packer

    Richard Guest

    Charles Packer <> 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
    Richard, Oct 9, 2007
    #2
    1. Advertising

  3. Charles Packer

    MQ Guest

    On Oct 9, 9:41 pm, 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);}
    >
    >


    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.
    MQ, Oct 9, 2007
    #3
  4. 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.
    Martin Ambuhl, Oct 9, 2007
    #4
  5. Charles Packer

    MQ Guest

    On Oct 9, 9:57 pm, Richard <> wrote:
    > Charles Packer <> 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.
    MQ, Oct 10, 2007
    #5
  6. On Oct 9, 3:33 pm, Martin Ambuhl <> 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
    Charles Packer, Oct 10, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lou Pecora
    Replies:
    6
    Views:
    67,635
    santoshreddy3
    Jul 7, 2011
  2. John Smith

    Header files included in header files

    John Smith, Jul 21, 2004, in forum: C Programming
    Replies:
    18
    Views:
    596
    Jack Klein
    Jul 24, 2004
  3. gk245
    Replies:
    2
    Views:
    1,189
    Christopher Benson-Manica
    May 6, 2006
  4. thinktwice
    Replies:
    3
    Views:
    332
    Daniel T.
    Feb 10, 2006
  5. Pietro Cerutti

    Header file included more than once?

    Pietro Cerutti, Aug 9, 2007, in forum: C Programming
    Replies:
    4
    Views:
    513
    Keith Thompson
    Aug 9, 2007
Loading...

Share This Page