![]() |
|
Logic Unknown - help needed - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.li/Forum-C-C-Obj-C) +--- Thread: Logic Unknown - help needed (/Thread-Logic-Unknown-help-needed) |
RE: Logic Unknown - help needed - ArkPhaze - 04-19-2013 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. 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;RE: Logic Unknown - help needed - ArkPhaze - 04-19-2013 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. 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;RE: Logic Unknown - help needed - Solixious - 04-19-2013 I see your point. Though I never experienced it practically till now, I'd know it if it happens in future. Thanks for explaining @Deque and @ArkPhaze
RE: Logic Unknown - help needed - Solixious - 04-19-2013 I see your point. Though I never experienced it practically till now, I'd know it if it happens in future. Thanks for explaining @Deque and @ArkPhaze
RE: Logic Unknown - help needed - Creed_mybb_import11544 - 04-20-2013 ok.. i got rid of DEV C++ and thanks for explaining |