RE: Logic Unknown - help needed 04-19-2013, 10:00 AM
#31
I did not read it, I only went by what my compiler was doing for the disassembly. I hate using Wikipedia as a reference for anything so I ignored that admittedly... ++y is the same as y = y + 1 or y += 1 however, but now that I have taken a look at the link, the only problem there is with y++ and not ++y.
@Solixious - No I was wrong (for what Deque was originally trying to point out anyway), I was right based on my direct view into the disassembly when I was viewing data in the registers for what I was debugging, but this, by what Deque was trying to say, is irrelevent because there's no way to tell that other compilers will read it the same way, so it would be bad practice to write code like that. My debugging was all I was going by however, and by specification, there are no sequence points other than ";" in x=(y++)+(++y);. Therefore y++ might increment y by 1 after this entire thing is evaluated, and thus you would end up with:
Visual Studio default compiler reads the expression right to left and that {variable}++ in the example above was being incremented before the next part of the expression.
This:
Should have been written (depending on what the intention was), something like this:
Code:
x=(y++)+(y=y+1);
// or
x=(y++)+(y+=1);
@Solixious - No I was wrong (for what Deque was originally trying to point out anyway), I was right based on my direct view into the disassembly when I was viewing data in the registers for what I was debugging, but this, by what Deque was trying to say, is irrelevent because there's no way to tell that other compilers will read it the same way, so it would be bad practice to write code like that. My debugging was all I was going by however, and by specification, there are no sequence points other than ";" in x=(y++)+(++y);. Therefore y++ might increment y by 1 after this entire thing is evaluated, and thus you would end up with:
Code:
x=(3)+(3+1);
// and now y is incremented from the time of y++
Visual Studio default compiler reads the expression right to left and that {variable}++ in the example above was being incremented before the next part of the expression.
This:
Code:
x=(y++)+(++y);
Should have been written (depending on what the intention was), something like this:
Code:
x = y;
y = y + 2;
x = x + y;
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]