This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Decrement


Hello,

I don't know exactly if we found a bug. I have no expierence in fill out bugzilla.

Our problem is the following line of code:
int x = 100;
x -= x-- - --x;

In my option the result should be 99 and was compiling with a gcc version 3.2.2 on SunOS (SUNW, Ultra4) and the result was 99.

My discussion partner said the result should be 98 and he showed me the result of another C-Compiler (Microsoft). Now I tried the programm in Java and the result was 98.

In my logic first 100 will predecrement to 99, now the postdecrement recognizes that the value x has change and postdecrement to 98. So the expression to the right is now x -= 98 - 99. Now this expression will compute x = 98 - (-1) => the result is 99.

In his logic first 100 will predecement to 99, now the value of 99 is used by the postdecrement and after this the decrement will execute to 98. The expression looks now like x -= 99 -99. The result is then x = 98 - 0 (x = 98 - (99 -99)).

We are not really computer gurus and I hope my English was good enough to understand the problem. If you say that's a bug, I will fill out a bugzilla report. If you say this should be then I'm looking forward for you explaination.

Thank you in advance

Markus Hofmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]