Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!custom!boykin From: boykin@custom.UUCP (Joseph Boykin) Newsgroups: comp.unix.wizards Subject: Re: Why doesn't this qsort example work? Message-ID: <770@custom.UUCP> Date: Tue, 20-Oct-87 13:24:25 EDT Article-I.D.: custom.770 Posted: Tue Oct 20 13:24:25 1987 Date-Received: Thu, 22-Oct-87 05:46:02 EDT References: <7527@g.ms.uky.edu> Organization: Custom Software Systems; Natick, MA Lines: 24 Summary: Wrong parameter to qsort In article <7527@g.ms.uky.edu>, sean@ms.uky.edu (Sean Casey) writes: > > I'm trying to use qsort(3) for the first time and I'm having a bit of > trouble. ...Bunch of stuff deleted... > qsort(&t[0], 2, sizeof(struct tstr), (*compar)()); The fourth (last) argument to qsort is the address of the function which will do the comparison. What you've done here is to *call* the function 'compar' without any arguments and the return value of that function call would be passed to qsort. The function isn't core dumping because of bogus values of 'a' as you stated, but because the pointers 'x' and 'y' within the function were using whatever garbage values were left over on the stack. The correct call to qsort would be: qsort(&t[0], 2, sizeof(struct tstr), compar); -- Joe Boykin Custom Software Systems ...necntc!custom!boykin