Error message explained

E

esclepius

In the following little bit of code, I understand what and why the
error is, ( lack of parentheses in *pp.y , thus declaring 'y' a
pointer, which it is not) but what I don't get is the error the
compiler raises.

int main (int argc, const char * argv[]) {

struct point {
int x;
int y;
};
struct point origin;
struct point *pp;

pp= &origin;

origin = makepoint(23, 67);

printf("%d, %d\n", (*pp).x, *pp.y); /*error: request for member 'y'
in something not a structure or union */

}


I am sure I will get this again at some point, so any logic here is
appreciated, or perhaps I am looking too deeply.

Thanks.
 
B

Bartc

In the following little bit of code, I understand what and why the
error is, ( lack of parentheses in *pp.y , thus declaring 'y' a
pointer, which it is not) but what I don't get is the error the
compiler raises.

int main (int argc, const char * argv[]) {

struct point {
int x;
int y;
};
struct point origin;
struct point *pp;

pp= &origin;

origin = makepoint(23, 67);

printf("%d, %d\n", (*pp).x, *pp.y); /*error: request for member 'y'
in something not a structure or union */

}

Since the parentheses seem to fix things, without them the term is
presumably parsed as:

*(pp.y)

which won't work because pp is a pointer, not a struct as expected. (*pp).y
works but best to use pp->y
 
M

mdh

which won't work because pp is a pointer, not a struct as expected. (*pp)..y
works but best to use pp->y

Thank you for that...just getting to the "->" operator.
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top