Article View: comp.bugs.4bsd
Article #11Re: Bug in "comm" utility
From: Maarten Litmaath
Date: Wed, 14 Jun 1989 19:00
Date: Wed, 14 Jun 1989 19:00
50 lines
1507 bytes
1507 bytes
gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
[quick kludge deleted, sorry Doug]
Why didn't you change compare()? The new version should be faster too!
/*
* old version
*/
compare(a,b)
char *a,*b;
{
register char *ra,*rb;
/*
* it's non-portable to move a pointer one position before the begin
* of the array: on segmented architectures &array[0] could be the
* start of a segment
*/
ra = --a;
rb = --b;
while(*++ra == *++rb) /* pre-increment instructions?! */
if(*ra == '\0')
return(0);
if(*ra < *rb)
return(1);
return(2);
}
/*
* new version - according to the ANSI standard a pointer may be moved one
* position PAST the end of the array
*/
int compare(a, b)
char *a, *b;
{
register char *ra, *rb;
ra = a;
rb = b;
while (*ra == *rb++) /* post-increment instructions!! */
if (!*ra++)
return 0;
return *ra < *--rb ? 1 : 2;
}
--
"I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam:
they're small." (Stephen Savitzky) |maart@cs.vu.nl, mcvax!botter!maart
Technical Details
Message-ID:
<2758@piraat.cs.vu.nl>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maartReferences:
<10396@smoke.BRL.MIL>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.bugs.4bsd,comp.bugs.sys5 Subject: Re: Bug in "comm" utility Keywords: UNIX "comm" bug fix Message-ID: <2758@piraat.cs.vu.nl> Date: 14 Jun 89 19:00:35 GMT References: <10396@smoke.BRL.MIL> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 50