Addition mathematically holds the associative property:
(a + b) + c = a + (b + c)
In the general case, this property does not hold for floating-point numbers because they represent values in a finite precision.
Is a compiler allowed to make the above substitution when generating machine code from a C program as part of an optimization? Where does it exactly say in the C standard?
The compiler is not allowed to perform “optimizations”, which would result in a different value computed, than the one computed according to abstract machine semantics.
In your example:
or even without the parentheses:
we have
and the compiler is required to generate code as if
ais summed withband the result is summed withc.