Could someone please explain me this error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Mahone

    Could someone please explain me this error?

    OK, I have this piece of code:

    void method(void* parameter)
    {
    1: struct Data* dataOfReference =(struct Data*)parameter ;
    2: Info tmpInfo=(*dataO fReference).pay load.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
  • Nick Keighley

    #2
    Re: Could someone please explain me this error?

    On May 2, 12:53 pm, Alexander Mahone <salvodanilogiu ffr...@gmail.co m>
    wrote:
    void method(void* parameter)
    {
    1:    struct Data* dataOfReference =(struct Data*)parameter ;
    2:    Info tmpInfo=(*dataO fReference).pay load.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

    Comment

    • Ian Collins

      #3
      Re: Could someone please explain me this error?

      Alexander Mahone wrote:
      OK, I have this piece of code:
      >
      void method(void* parameter)
      {
      1: struct Data* dataOfReference =(struct Data*)parameter ;
      2: Info tmpInfo=(*dataO fReference).pay load.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.

      Comment

      • Richard Tobin

        #4
        Re: Could someone please explain me this error?

        In article <f90e4f94-9061-42c8-b2e2-b2e8541e0d82@x4 1g2000hsb.googl egroups.com>,
        Alexander Mahone <salvodanilogiu ffrida@gmail.co mwrote:
        >void method(void* parameter)
        >{
        >1: struct Data* dataOfReference =(struct Data*)parameter ;
        >2: Info tmpInfo=(*dataO fReference).pay load.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

        Comment

        • Peter Nilsson

          #5
          Re: Could someone please explain me this error?

          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=(*dataO fReference).pay load.data;
          Easier on the eye is...

          Info tmpInfo = dataOfReference->payload.data ;

          --
          Peter

          Comment

          • Igmar Palsenberg

            #6
            Re: Could someone please explain me this error?

            void method(void* parameter)
            {
            1: struct Data* dataOfReference =(struct Data*)parameter ;
            This cast is bogus, and hides real bugs.
            2: Info tmpInfo=(*dataO fReference).pay load.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.

            Comment

            Working...