Re: Associativity of ++ and --



On 27 Sep 2006 20:13:47 -0700, "Chad" <cdalten@xxxxxxxxx> wrote:

The following question stems from p.132 in the book "The C Programming
Language", second edition by K & R.

The have

struct {
int len;
char *str;
} *p;

The question is how come parentheses are need when you go like:
(++p)->len;

but you don't need them when you go:
p++->len;

<..>

It is only a question of natural evaluation of expressions and
precedence of operators.

In the second case, it is only natural that ++ affects p, there is no
way it could affect ->len.

In the first case, operator -> has higher precedence than operator ++.
Thus, ++p->len should be parsed as ++(p->len)

regards,

zara
.