Re: Associativity of ++ and --
- From: Zara <me_zara@xxxxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 06:02:17 +0200
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
.
- References:
- Associativity of ++ and --
- From: Chad
- Associativity of ++ and --
- Prev by Date: Re: C99 Versus ANSI.
- Next by Date: Re: the difeirent bettwen the function open() with two an three parameters
- Previous by thread: Associativity of ++ and --
- Next by thread: Re: Associativity of ++ and --
- Index(es):