Error message explained

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • esclepius@gmail.com

    #1

    Error message explained

    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.
  • Bartc

    #2
    Re: Error message explained

    <esclepius@gmai l.comwrote in message
    news:cda404cf-28c7-4fd5-ac28-1c26ddd5de7f@l3 3g2000pri.googl egroups.com...
    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

    --
    Bartc

    Comment

    • mdh

      #3
      Re: Error message explained

      On Aug 23, 9:01 am, "Bartc" <b...@freeuk.co mwrote:
      >
      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.

      Comment

      Working...