Error message explained

M

mdh

I understand *why* this produces an error and how to correct it, (add
parentheses) but the error itself is a bit eclectic? As I am sure this
will arise again, could anyone throw some logic at it.

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


struct point {
int x;
int y;
};

struct point *pp;
struct point origin;
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*/

}

Thanks in advance
 
V

vippstar

I understand *why* this produces an error and how to correct it, (add
parentheses) but the error itself is a bit eclectic? As I am sure this
will arise again, could anyone throw some logic at it.

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

struct point {
int x;
int y;

};

struct point *pp;
struct point origin;
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*/

}

See operator precedence.
.. bounds tigher than *

*pp.y means *(pp.y)

pp is a pointer, . requires structure or union
 
M

mdh

mdh said:
I understand *why* this produces an error and how to correct it,
snip

int main (int argc, const char * argv[]) {
struct point {
   int x;
   int y;
};
   struct point *pp;
   struct point origin;
   pp= &origin;
   printf("%d, %d\n", (*pp).x, *pp.y);  /*error: request for member 'y'
in something not a structure or union*/


It's a snytax error. As written *pp.y assumes pp a structure and y a
pointer to int. None of that is true.

Thanks Joe...yes that makes sense. One more eclectism falls :)
 
H

Harald van Dijk

mdh said:
struct point *pp;
[...]
printf("%d, %d\n", (*pp).x, *pp.y); /*error: request for member 'y'
in something not a structure or union*/
It's a snytax error.

No, it's not, unless snytax is an intentional misspelling that I am not
familiar with. *pp.y is syntactically valid, but semantically invalid.
 
G

gw7rib

I understand *why* this produces an error and how to correct it, (add
parentheses) but the error itself is a bit eclectic? As I am sure this
will arise again, could anyone throw some logic at it.

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

struct point {
        int x;
        int y;

};

        struct point *pp;
        struct point origin;
        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*/

}

Thanks in advance

Erm, it seems to make perfect sense to me. The '.' means you are
accessing a member of a struct or union, so pp.y means "access the
member called 'y' of the struct or union pp". Which is wrong, beacause
pp is not a struct or union - it is a pointer to a struct. So pp isn't
a struct or a union, and it doesn't have members. So it's an error to
access member 'y' of it.
 

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,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top