For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > assisiative operators









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author assisiative operators
Onno Garms

2006-01-24, 7:07 pm

Hello,

I found out that Microsoft Visual C++ .NET (Visual Studio 7.0) changes
the order of evaluation in expressions like

double a,b,c,d;
d = a+b+c;

AFAIK, this should be evaluated as (a+b)+c, see for example
> http://groups.google.de/group/comp....adf77dc5?hl=de&


However, on the following lines of code, the compiler computes a+(b+c)
in release mode. Debug mode works correctly.

double dx,dy;
x = p.x + (dx=(x-p.x))*w.cosine() - (dy=(y-p.y))*w.sine();
y = p.y + dx*w.sine() + dy*w.cosine();

Two questions:
1. Am I right that this is a bug in the compiler?
2. Is there a
- fix
- workaround by compiler option (other than disabling all
optimization)
- tool to find all such sums in tens of thousands line
of code, enabling me so insert parenthesis everywhere

TIA,
Onno Garms

Igor Tandetnik

2006-01-24, 7:07 pm

Onno Garms <onno.garms@scai.fraunhofer.de> wrote:
> I found out that Microsoft Visual C++ .NET (Visual Studio 7.0) changes
> the order of evaluation in expressions like
>
> double a,b,c,d;
> d = a+b+c;
>
> AFAIK, this should be evaluated as (a+b)+c, see for example
>
> However, on the following lines of code, the compiler computes a+(b+c)
> in release mode. Debug mode works correctly.


This is an optimization which is indeed not strictly conformant. You can
disable it with /Op switch.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com