But, in the first one, o is set to o - 1 after the statement is fully ran by the compiler. In the second one, o is set to o -1 before the statement is ran by the compiler.
Rob Loach Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - The Boondock Saints
Yes those two have the same end result, but it behaves differently if both expressions o-- and --o appear as subexpressions in a larger expression, for instance in your example "--o - o--". Which one gets evaluated first? The C++ standard simply doesn''t define that.
To simplify things a bit, it''s much like this expression: o = f() - g(); Which function gets called first, f or g? According to the C++ standard it depends on your compiler.
What if f modifies the value of o (via a pointer for argument''s sake) and g uses the value of o (also via a pointer) when calculating its return value? What happens? Does f get called first, modify o, and then g uses the modified value? Or does g get called first and use the original value, then f is called and modifies it?
Anyway it''s getting late, I got work tomorrow, and I''m getting kind of sick of trying to convince you guys.
quote:Original post by siaspete I think it''s a non-issue anyway. If you write code like that you''ll probably be sacked in a couple of days!
I was just going to say that. You pull a stunt like this one in our company, and you''ll be looking for a new job the next day. I guess that most other software companies will handle this in a similar harsh way.
quote: What''s so undefined about that? Most compilers will do it like this- the fact that they don''t have to isn''t very practical. Unless you are participating in the GNU project, you are probably using one or two compilers on one or two platforms, and you don''t need to worry about stuff like the standard all the time.
You would have fun in the industry (not). Relying on undefined behaviour is one of the capital sins in software engineering. As someone mentioned above, imagine a 1m+ LOC project that will suddendly break on a new/different compiler setup. The costs of fixing idiotic abominations as the "--o - o--" one can cost millions. It could even ruin the company.