Could someone please explain me this error?

Discussion in 'C Programming' started by Alexander Mahone, May 2, 2008.

  1. OK, I have this piece of code:

    void method(void* parameter)
    {
    1: struct Data* dataOfReference=(struct Data*)parameter;
    2: Info tmpInfo=(*dataOfReference).payload.data;
    3: char* message;
    ....
    }

    Why does the compiler (gcc) complain about line 2?

    'error: dereferencing pointer to incomplete type'

    Shouldn't it be correct? I have a pointer, and I dereference it with
    '*'...
    Thanks
     
    Alexander Mahone, May 2, 2008
    #1
    1. Advertising

  2. On May 2, 12:53 pm, Alexander Mahone <>
    wrote:

    > void method(void* parameter)
    > {
    > 1:    struct Data* dataOfReference=(struct Data*)parameter;
    > 2:    Info tmpInfo=(*dataOfReference).payload.data;
    > 3:    char* message;
    > }
    >
    > Why does the compiler (gcc) complain about line 2?
    >
    > 'error: dereferencing pointer to incomplete type'
    >
    > Shouldn't it be correct? I have a pointer, and I dereference it with
    > '*'...


    what is the definition of struct Data?

    --
    Nick Keighley
     
    Nick Keighley, May 2, 2008
    #2
    1. Advertising

  3. Alexander Mahone

    Ian Collins Guest

    Alexander Mahone wrote:
    > OK, I have this piece of code:
    >
    > void method(void* parameter)
    > {
    > 1: struct Data* dataOfReference=(struct Data*)parameter;
    > 2: Info tmpInfo=(*dataOfReference).payload.data;
    > 3: char* message;
    > ....
    > }
    >
    > Why does the compiler (gcc) complain about line 2?
    >
    > 'error: dereferencing pointer to incomplete type'
    >

    Is the complete definition of struct Data (not just a forward
    declaration) visible to the compiler? It looks like you have left out a
    header file.

    --
    Ian Collins.
     
    Ian Collins, May 2, 2008
    #3
  4. In article <>,
    Alexander Mahone <> wrote:

    >void method(void* parameter)
    >{
    >1: struct Data* dataOfReference=(struct Data*)parameter;
    >2: Info tmpInfo=(*dataOfReference).payload.data;


    Where's the definition of struct Data?

    >Why does the compiler (gcc) complain about line 2?
    >
    >'error: dereferencing pointer to incomplete type'
    >
    >Shouldn't it be correct? I have a pointer, and I dereference it with
    >'*'...


    You have a pointer to a struct Data, and to dereference it you
    need a definition of that struct. Presumably you don't have one.

    -- Richard
    --
    :wq
     
    Richard Tobin, May 2, 2008
    #4
  5. Alexander Mahone wrote:
    > 1: struct Data* dataOfReference=(struct Data*)parameter;


    If you need the cast, then there's a chance this is wrong.

    > 2: Info tmpInfo=(*dataOfReference).payload.data;


    Easier on the eye is...

    Info tmpInfo = dataOfReference->payload.data;

    --
    Peter
     
    Peter Nilsson, May 3, 2008
    #5

  6. > void method(void* parameter)
    > {
    > 1: struct Data* dataOfReference=(struct Data*)parameter;


    This cast is bogus, and hides real bugs.

    > 2: Info tmpInfo=(*dataOfReference).payload.data;
    > 3: char* message;
    > ...
    > }
    >
    > Why does the compiler (gcc) complain about line 2?


    because it doesn't now what struct Data looks like, hence the 'incomplete'.



    Igmar.
     
    Igmar Palsenberg, May 5, 2008
    #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. Gactimus
    Replies:
    22
    Views:
    742
    jeffc
    Dec 15, 2004
  2. Replies:
    5
    Views:
    305
    Bo Persson
    Jan 10, 2006
  3. wkevin
    Replies:
    4
    Views:
    606
    Edward A. Falk
    Nov 7, 2011
  4. Rubyist
    Replies:
    1
    Views:
    112
    Ross Bamford
    Feb 2, 2006
  5. John Small
    Replies:
    4
    Views:
    124
    John Small
    Feb 2, 2009
Loading...

Share This Page