lkml.org 
[lkml]   [1998]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: 'C' Operators precedence
Date
Followup to:  <Pine.LNX.3.95.980519212238.363A-100000@chaos.analogic.com>
By author: "Richard B. Johnson" <root@chaos.analogic.com>
In newsgroup: linux.dev.kernel
>
> When seeing:
>
> a = f(b) + g(c);
>
> ... the compiler is still not free to evaluate 'b' and 'c'
> in any order because of association, also called
> associativity, which requires operators of identical
> precedence to be evaluated left-to-right. This is why the
> functions (or macros) will be evaluated left-to-right.
>

Incorrect. Associativity just means that (for example):

a = b - c - d;

... must evaluate as:

a = (b - c) - d;

rather than:

a = b - (c - d);

However, for *ANY* of these expressions, the compiler is free to
evaluate b, c, or d in any order it darn well pleases; associativity
only controls how the results are to be combined.

> When seeing:
>
> a = b() + c();
>
> .... the compiler is told to evaluate nothing (void) using
> object 'b', then evaluate nothing using object 'c'.
>
> When seeing:
>
> a = b + c + d;
>
> ... the compiler may still not legally evaluate the objects
> in any order because of associativity, but many/most do.
> Optimization is not yet part of the 'C' standard. When
> attempting to optimize code, certain standards are broken as
> long as the code is likely to work.
>
> Everything makes sense once one understands the '()' operator.

This is just plain WRONG. The C standard is very explicit that there
are no sequence points between the evaluation of the arguments of
addition; in fact, only a few operators have any serialization
property; && and || does, and maybe (I am not sure about this one) the
assignment operators.

-hpa
--
PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD 1E DF FE 69 EE 35 BD 74
See http://www.zytor.com/~hpa/ for web page and full PGP public key
I am Bahá'í -- ask me about it or see http://www.bahai.org/
"To love another person is to see the face of God." -- Les Misérables

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.109 / U:27.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site