pcg@xxxxxxxx ( Marc) (A.) (Lehmann ) wrote:
For example, in C, the compiler is legally allowed to transform:
r = (1 - a) * b;
into:
r = a - a * b;
Which might not be the same value. If that is a problem, you either have to use more sequence points (i.e. multiple statements), or you need to use fortran, where these kinds of transformations are not allowed :)
I assume you mean r = b - a * b, but even then that's the first I see something like this. AFAIK that is not what sequence points do. In
(1 - a()) * b()
a() might be evaluated before b() or the other way around, you never know. Sequence points ensure that everything before them is executed first.
That's what I know sequence points are for; I would be very much surprised if the compiler is allowed to do symbolic algebra. I could be wrong of course (it wouldn't be the first time). Do you have any pointers to relevant online resources?
-- "Codito ergo sum" Roel Schroeven