www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/28/14:34:06

From: Radical DOT NetSurfer AT delorie DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Please add strrev proposal
Date: Fri, 28 Sep 2001 14:25:02 -0400
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <m1g9rtociqgunetpgm7qb5106m3sqvhpor@4ax.com>
References: <lcq8rtk1nqua2hc6rqfhmqisbd587n8t2n AT 4ax DOT com> <Xns912A8823C1399ASINANUNUR AT 132 DOT 236 DOT 56 DOT 8>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
X-Complaints-To: newsabuse AT supernews DOT com
Lines: 71
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

in my humble opinion, its NONstandard that Libc doesn't already have
this.  Please name one other C/C++ compiler that also omits it?

On 28 Sep 2001 17:23:00 GMT, "A. Sinan Unur" <asu1 AT cornell DOT edu> wrote:

>Radical NetSurfer wrote in
>news:lcq8rtk1nqua2hc6rqfhmqisbd587n8t2n AT 4ax DOT com: 
>
>> I would like to encourage everyone who has a need for
>> strrev to come forward and encourage the maintainers of
>> LIBC used with GCC to kindly add   strrev.
>
>Count me against this if for no other reason that the fact that I do not 
>like extra nonstandard function which solve tiny problems. If you need the 
>functionality, you can write one for your own situation. If it is going to 
>be added to a library, the solution needs to be useful to more than just 
>one person in a particular situation. 
>
>Anyway, the main point of my post, however, is to point out just one of the 
>gotchas with these kinds of functions.
>
>You give the following usage example:
>
>> Example
>> printf("The reverse of %s is %s\n", str,  strrev(str) );
>
>Hmmmmm  ..... let us see using the code you suggested:
>
>/* +++Date last modified: 05-Jul-1997 */
>/*
>**  STRREV.C - reverse a string in place
>**
>**  public domain by Bob Stout
>*/
>
>#include <string.h>
>#include <stdlib.h>
>#include <stdio.h>
>
>char *strrev(char *str) {
>	char *p1, *p2;
>	
>	if (! str || ! *str) return str;
>	
>	for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) 
>	{
>		*p1 ^= *p2;
>		*p2 ^= *p1;
>		*p1 ^= *p2;
>	}
>	
>	return str;
>}
>
>int main(void)
>{
>	char s[] = "This is a test.";
>
>	printf("Original String: %s\nReversed String:%s\n", s, strrev(s));
>
>	return 0;
>}
>
>C:\var>gcc djstrrev.c -o djstrrev.exe -O2 -Wall
>
>C:\var>djstrrev
>Original String: .tset a si sihT
>Reversed String: .tset a si sihT
>
>Now, think about that.	

- Raw text -


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