www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/29/04:59:49

Date: Sat, 29 Sep 2001 10:56:03 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <2110-Sat29Sep2001105602+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9
In-reply-to: <vhpart0gjqnr7u2tf0ih8hdf18mlkj11br@4ax.com>
(Radical DOT NetSurfer AT delorie DOT com)
Subject: Re: Please add strrev proposal
References: <lcq8rtk1nqua2hc6rqfhmqisbd587n8t2n AT 4ax DOT com> <Xns912A8823C1399ASINANUNUR AT 132 DOT 236 DOT 56 DOT 8> <3BB50884 DOT 347A4384 AT yahoo DOT com> <hmjart4m6h7tt0vddvvg47438dijr428ob AT 4ax DOT com> <3BB55487 DOT CC4407ED AT worldnet DOT att DOT net> <vhpart0gjqnr7u2tf0ih8hdf18mlkj11br AT 4ax DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: Radical DOT NetSurfer AT delorie DOT com
> Newsgroups: comp.os.msdos.djgpp
> Date: Sat, 29 Sep 2001 02:13:50 -0400
> 
> OUTCH! you believe this behavior is correct, too?

Of course, it's correct!  That's how a C compiler is supposed to
work.  _Any_ C compiler, including Borland's.  Namely, all the
arguments of a function are computed _before_ the function is called.

Since one of the arguments to printf calls strrev, strrev is called
before printf is called.  Since the value returned by strrev is the
same as its argument (both are pointers to the same storage), if you
want to print the original and the reversed strings, you need to do
this:

    printf ("Orig: %s\n", s);
    printf ("Rev:  %s\n", strrev (s));

That is, you need to print the original string _before_ you write any
expression which includes a call to strrev.

> psst: that returns the last static value of a func, in this
> case, whatever the last string that was "reversed"

That's not how Borland's documentation defines strrev.  It explicitly
says: "...strrev returns its argument `str'".  The implementation you
suggested contradicts this specification.

- Raw text -


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