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);
    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
    Alexander Mahone, May 2, 2008
    1. Advertisements

  2. what is the definition of struct Data?
    Nick Keighley, May 2, 2008
    1. Advertisements

  3. Alexander Mahone

    Ian Collins Guest

    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, May 2, 2008
  4. Where's the definition of struct Data?
    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
    Richard Tobin, May 2, 2008
  5. If you need the cast, then there's a chance this is wrong.
    Easier on the eye is...

    Info tmpInfo = dataOfReference->;
    Peter Nilsson, May 3, 2008
  6. This cast is bogus, and hides real bugs.
    because it doesn't now what struct Data looks like, hence the 'incomplete'.

    Igmar Palsenberg, May 5, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.