424,963 Members | 1,276 Online
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

# dereference precedence

 P: n/a Hi, This has probably debated here before but I could not find it in Google. Though I don't have the standard at hand I've seen several references point that operator -> has higher precedence than unary * (dereference). Then I would always have thought that *a->b Is equivalent to (*a)->b but apparently it should be *(a->b) Which which is right and why? Thanks, Toni Apr 13 '06 #1
4 Replies

 P: n/a Though I don't have the standard at hand I've seen several references point that operator -> has higher precedence than unary * (dereference). That's right... Then I would always have thought that *a->b Is equivalent to (*a)->b No, if this is the case then * has a higher precedence that -> which contradict what you said above. Also this is meaningless, it should be (*a).b but apparently it should be *(a->b) Which which is right and why? The second one Thanks, Welcome.. Abdo Haji-Ali Programmer In|Framez Apr 13 '06 #2

 P: n/a > > (*a)->b No, if this is the case then * has a higher precedence that -> which contradict what you said above. Also this is meaningless, it should be (*a).b Silly me, I just assumed that 'a' is a one-level pointer, which is not necessarily... Sorry Abdo Haji-Ali Programmer In|Framez Apr 13 '06 #3

 P: n/a En/na Abdo Haji-Ali ha escrit: (*a)->b No, if this is the case then * has a higher precedence that -> which contradict what you said above. This is just what I thought, it was just one of those occasions where the feelings contradict the logic. As (nearly) always the logic turns out to be right. Thanks Toni Apr 13 '06 #4

 P: n/a Abdo Haji-Ali wrote: Though I don't have the standard at hand I've seen several references point that operator -> has higher precedence than unary * (dereference). That's right... Then I would always have thought that *a->b Is equivalent to (*a)->b No, if this is the case then * has a higher precedence that -> which contradict what you said above. Also this is meaningless, it should be (*a).b (*a)->b is not necessarily meaningless. #include int main(void) { struct foo { int b; } c[1]; struct foo *a[1]; c[0].b = 3; a[0] = c; printf("%d\n", (*a)->b); } Apr 13 '06 #5

### This discussion thread is closed

Replies have been disabled for this discussion.