Could someone please explain me this error?

  • Thread starter Alexander Mahone
  • Start date
A

Alexander Mahone

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
 
N

Nick Keighley

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?
 
I

Ian Collins

Alexander said:
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.
 
R

Richard Tobin

Alexander Mahone said:
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
 
P

Peter Nilsson

Alexander said:
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;
 
I

Igmar Palsenberg

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.
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top