Increment/decrement operator bugs

Miguel A. Quintans miguel.quintans@uah.es
Thu Sep 25 17:44:00 GMT 2008


Hello

The result of  an expression using pre-decrement or pre-increment such as:
        y = x * n * --n;
gives different results in a few cases where x is placed before or after 
the rest, or when its value is 1 or not. Please run the program attached 
where a comment indicates what we think works wrong. We obtain:

1.- 16
2.- 16
3.- 16
4.- 40
5.- 20
6.- 16
7.- 40
8.- 32
1.- 36
2.- 36
3.- 36
4.- 60
5.- 30
6.- 36
7.- 60
8.- 72

In contrast, the results we get running it in a AIX Computer with the 
native compiler (IBM XL C/C++ Enterprise Edition for AIX, V9.0 Version: 
09.00.0000.0000) is what we expected:

1.- 20
2.- 20
3.- 20
4.- 40
5.- 20
6.- 20
7.- 40
8.- 40
1.- 30
2.- 30
3.- 30
4.- 60
5.- 30
6.- 30
7.- 60
8.- 60

We have experienced this issue in several versions of the gcc compiler 
(the ones distributed under fedora cores 6, 7, 8, knoppix 5.0.1 and also 
in the windows Dev-c++ 4.9.9.2 package compiler) obtaining the same 
results, that we think are (obviously) wrong.

We remain expectant of any comment from you.

Best regards

Miguel Ángel Quintáns & Virginia Escuder
Professors at the Universidad de Alcalá
Madrid
Spain

-------------- next part --------------
A non-text attachment was scrubbed...
Name: error compilador.c
Type: text/x-csrc
Size: 917 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20080925/30a35bd2/attachment.bin>


More information about the Gcc-bugs mailing list