Message-ID: <3BB4052E.954A4F69@yahoo.com> From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Benchmark Testing References: <9osdbt$r8k$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <9ov09c$gig$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <4634-Thu27Sep2001154412+0300-eliz AT is DOT elta DOT co DOT il> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 90 Date: Fri, 28 Sep 2001 06:39:02 GMT NNTP-Posting-Host: 12.90.167.159 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc06-news.ops.worldnet.att.net 1001659142 12.90.167.159 (Fri, 28 Sep 2001 06:39:02 GMT) NNTP-Posting-Date: Fri, 28 Sep 2001 06:39:02 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Radical, NetSurfer wrote: (and topposted, fixed) > > On Thu, 27 Sep 2001 15:44:13 +0200, "Eli Zaretskii" > wrote: > > >> From: Radical DOT NetSurfer AT delorie DOT com > >> Newsgroups: comp.os.msdos.djgpp > >> Date: Thu, 27 Sep 2001 09:06:49 -0400 > >> > >> PLEASE libc.a people, __add__ strrev() its been missing for far too > >> long. Thanks. > > > >It's on my TODO. > > /* > ** STRREV.C - reverse a string in place > ** > ** public domain by Bob Stout > */ > 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; > } > > and how does the above code compare to, whats below, > in terms of CPU time, and memory-access, etc? > > /* ======================= */ > /* reverse string in place */ > char *strrev(char *string) { void str... > char *last, temp; > > last = string + strlen(string); /* points to '\0' */ > while (last-- > string) { > temp = *string; *string++ = *last; *last = temp; > } > return (char*)string; /* NO SUCH LINE */ > > } /* strrev */ Kindly do not alter the code I published to make it incorrect without claiming the credit for the alterations. My function returned void. Also, kindly do NOT toppost. > > strrev(), according to every compiler I've seen that supports it, > always returns a pointer to the modified string. If such a return is really desirable (which I question), my code can be modified as follows: /* ======================= */ /* reverse string in place */ char *strrev(char *string) { char *last, *str, temp; last = string + strlen(string); /* points to '\0' */ str = string; while (last-- > str) { temp = *str; *str++ = *last; *last = temp; } return string; } /* strrev */ What you did not point out is that Bob Stouts code guards against a NULL input pointer, and mine does not. Neither do most library implementations of string routines. They are expected to operate on strings, not NULL pointers. Guarding the while with "if (str)" adds that feature, if desired. A point for the language mavens: If char is a signed type, then are the xor operators necessarily valid in Bobs code? In practice, I would expect them to work. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net) (Remove "XXXX" from reply address. yahoo works unmodified) mailto:uce AT ftc DOT gov (for spambots to harvest)