Re: What is a sequence point?

From: Mark McIntyre (markmcintyre_at_spamcop.net)
Date: 02/11/05


Date: Fri, 11 Feb 2005 22:30:48 +0000

On 11 Feb 2005 12:55:34 -0800, in comp.lang.c , "Luke Wu"
<LookSkywalker@gmail.com> wrote:

>
>infobahn wrote:

>> So what? The compiler can view it this way:
>>
>> "We have an expression of the form a = b = c; fine, I'll make them
>> all equal, so we'll set a equal to c and we'll set b equal to c",
>> so it could set p equal to q and then set p->next equal to q, with
>> the result that q->next = q;
>>
>No, the compiler views it according to the associativity rules(right to
>left) as this:
>
>(a = (b = c)) <=== right to left associativity

The standard discusses this type of problem. In 5.1.2.3, it shows examples
and notes that in general you cannot assume the normal mathematical laws of
associativity to be applicable.

-- 
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>


Relevant Pages

  • Re: Function call evaluation order
    ... How do you propose to explain in terms of precedence and associativity the ... define the order of evaluation for expressions like f1 or f2. ... Your expectations have been tuned to match what your compiler does! ... Undefined behavior is behavior that is not defined by the C++ standard. ...
    (microsoft.public.vc.language)
  • Re: Function call evaluation order
    ... How do you propose to explain in terms of precedence and associativity the ... Your expectations have been tuned to match what your compiler does! ... Undefined behavior is behavior that is not defined by the C++ standard. ...
    (microsoft.public.vc.language)
  • Re: Undefined Behavior. ..
    ... Operator associativity only defines how the expression should be _parsed_, i.e. it says which operand belong to which operator, but it introduces no temporal ordering on the actual computations whatsoever. ... This means that the compiler has to evaluate the following intermediate values ... Now the important part is that there's absolutely no ordering requirements on the side effects, meaning that the compiler is free to realize these side effects in any order and at any moment after they are introduced. ...
    (comp.lang.c)
  • Re: Undefined Behavior. ..
    ... Operator associativity only defines how the expression should be _parsed_, i.e. it says which operand belong to which operator, but it introduces no temporal ordering on the actual computations whatsoever. ... This means that the compiler has to evaluate the following intermediate values ...
    (comp.lang.c)
  • Re: operators similar to functions?
    ... Of course Harbison & Steele could be wrong, or the standard may ... The first one has 'a' as it's left operand, ... each additive expression have as it's value the sum of it's operands. ... thing that breaks the associativity of computer addition. ...
    (comp.lang.c)