Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average
Thread Closed 


Logic Unknown - help needed filter_list
Author
Message
RE: Logic Unknown - help needed #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.

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 ]


RE: Logic Unknown - help needed #32
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;
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]


RE: Logic Unknown - help needed #33
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 Smile
Folow me on My YouTube Channel if you're into art.


RE: Logic Unknown - help needed #34
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 Smile
Folow me on My YouTube Channel if you're into art.


RE: Logic Unknown - help needed #35
ok.. i got rid of DEV C++ and thanks for explaining








Users browsing this thread: 1 Guest(s)