Optimization trouble

Alexandre Oliva oliva@dcc.unicamp.br
Fri Dec 18 12:45:00 GMT 1998


On Oct 23, 1998, Christopher Weth <weth@tat.physik.uni-tuebingen.de> wrote:

> when compiling the litte program below without optimization (-O or -O2),
> it prints the right results; when optimization is turned on, the results
> become funny...

>     *(t1++) = *(t1-1)+sin(th);

This invokes undefined behavior, because you're reading a variable
(t1) and modifying it between two sequence points, and the read value
isn't used to compute the new value.

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc-bugs mailing list