On Thu, 12 Feb 2004 14:40:56 +0100, "Martin Johansen"
<ma******@is.online.no> wrote:
"Martin Dickopp" <ex****************@zero-based.org> wrote in message
news:c0*************@news.t-online.com... mo************@msn.com (Mohanasundaram) writes:
> I read somewhere that there is no uniform associativity in C.
> What is the author trying to convey? First of all I don't understand
> the meaning of assiciativity. Please help.
Associativity describes how subexpressions involving two or more
operators of same precedence are grouped. For example, the expression
a - b + c
behaves as
(a - b) + c
which is called left-to-right associativity
Yes, but it would be true to say right-to-left here as well. There is
allways right-to-left associativity in C to my understanding.
This discussion has some parallels to one I've been involved with in
alt.comp.lang.learn.c-c++ recently (like, now). The focus there has
been on the unary ops, but it may have some bearing on where you may
have picked up the misconception above.
The way I learned, and have been teaching, precedence and
associativity has been to say that the main gaggle of unary ops up at
the top of the table (++, -- *, &, et. al.) have /equal/ precedence,
and that conflicts are resolved by applying right-to-left
associativity.
I've been informed there's /another/ equally valid way to perceive
precedence for those unary ops: to say that postfix operators have
higher precedence than prefix operators, and there's no need for any
concept of "associativity" wrt those operators.
In any case, that doesn't change the fact that left-to-right
associativity is cut-and-dried for the binary arithmetic / logical
operators.
Leor Zolman
BD Software
le**@bdsoft.com www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at
www.bdsoft.com/tools/stlfilt.html