Mail Archives: djgpp/2001/09/29/04:59:49
> 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 -