Article View: comp.sys.mac
Article #15295Style bugs in LightSpeed C libraries
From: oster
Date: Fri, 27 Mar 1987 10:54
Date: Fri, 27 Mar 1987 10:54
43 lines
2432 bytes
2432 bytes
There are a few "bugs" in the LightSpeed C libraries. They don't produce
the wrong answer, they are just funky C.
example: look at the code for quicksort.
1.) bad algorithm: it picks the first element of the array as the pivot
element. This means that is you qsort an array that is
a.) already sorted or
b.) sorted in reverse order
c.) almost sorted.
qsort will run in N*N time instead of N*Ln(N) time. If they'd picked the
middle element, it would have run in N*ln(N) time in the three common
cases listed above.
2.) bad C style. look at the comparison function (I quote from memory:) it
looks like:
int compar(a, b){
comparX(a, b);
}
and the value of compar is used by its caller. The correct code is:
int compar(a, b){
return comparX(a, b);
}
The only reason the LSC code works is because comparX leaves its value in
the function return register (rD0), and compar doesn't clobber it before
returning itself. Lint (if it existed for LightSpeed C) would have caught
this. Since this error was in the released code, we can infer that the
libraries weren't checked with lint and that the compiler probably wasn't
either. LightSpeed C is far and away the best compiler for the Macintosh.
A simple way for Think, Inc to increase the quality of their product is
just make it pass lint. (and while your at it, could you make it an
option? I'll buy it.)
I want to say thank you to all the folks at Think who have produced a
wonderful product. And a special thanks for sending us library source
code, so we can find and fix minor blemishes like these.
--- David Phillip Oster -- "We live in a Global Village."
Arpa: oster@lapis.berkeley.edu --
Uucp: ucbvax!ucblapis!oster -- "You are Number Six."
Technical Details
Message-ID:
<2944@jade.BERKELEY.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ucbcad!ucbvax!jade!lapis.berkeley.edu!osterReferences:
<306@umbc3.UMD.EDU> <307@umbc3.UMD.EDU>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ucbcad!ucbvax!jade!lapis.berkeley.edu!oster From: oster@lapis.berkeley.edu.UUCP Newsgroups: comp.sys.mac Subject: Style bugs in LightSpeed C libraries Message-ID: <2944@jade.BERKELEY.EDU> Date: Fri, 27-Mar-87 05:54:57 EST Article-I.D.: jade.2944 Posted: Fri Mar 27 05:54:57 1987 Date-Received: Sun, 29-Mar-87 07:49:02 EST References: <306@umbc3.UMD.EDU> <307@umbc3.UMD.EDU> Sender: usenet@jade.BERKELEY.EDU Reply-To: oster@lapis.berkeley.edu (David Phillip Oster) Organization: University of California, Berkeley Lines: 43 Keywords: buggies!