Mail Archives: djgpp/2001/10/01/05:49:49
Note: Posting the program's output would have been more helpful
than another rant.
> I just can not believe what my dainty eyes behold before me!!
> (I must of been crazy to buy software from that little green man...)
>
> cout << "S1: " << r << " S2: " << strrev(r) << endl;
Shifts are evaluated right-to-left (which is one of the reasons they
were chosen as in/output operators in C++). So your strrev(r) still
gets evaluated first. As a result, by the time r is printed, it has
already been reversed.
Note that is _not_ the "mechanical" and rather "sloppy" way that
earlier 'C/C++' compilers functioned. It is the normal way pointers
work. The stack holds the value you push; if you push an address,
it holds that address, regardless of whether or not the memory it
points to gets modified. Even objects won't save you here - the
function call that reverses the string object in-place would still
get evaluated first. Of course, with objects, the reversal function
would most likely not work in-place.
- Raw text -