www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/01/05:49:49

Message-ID: <3BB83798.E2BD52BB@falconsoft.be>
Date: Mon, 01 Oct 2001 11:30:00 +0200
From: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
Organization: Anubex (www.anubex.com)
X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.2.16-3 i686)
X-Accept-Language: en, nl-BE, nl
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf vs stream IO
References: <foubrto6s9c5nltt00ad6sg5pv70ppohvg AT 4ax DOT com>
Lines: 21
NNTP-Posting-Host: 194.78.64.238
X-Trace: 1001928637 reader1.news.skynet.be 36457 194.78.64.238
X-Complaints-To: abuse AT skynet DOT be
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019