Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ukma!eric From: eric@ms.uky.edu (Eric Herrin) Newsgroups: comp.unix.wizards Subject: Re: Why doesn't this qsort example work? Message-ID: <7528@e.ms.uky.edu> Date: Mon, 19-Oct-87 10:08:49 EDT Article-I.D.: e.7528 Posted: Mon Oct 19 10:08:49 1987 Date-Received: Tue, 20-Oct-87 02:32:17 EDT References: <7527@g.ms.uky.edu> Reply-To: eric@ms.uky.edu (Eric Herrin) Organization: U of Kentucky, Mathematical Sciences Lines: 35 Keywords: argh, frustration, core dump Summary: function addresses and calls >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. I've included some code here that reproduces the problem. >The following C program coredumps because compar() is being called with >bogus arguments. I'm sure it's my fault, but I just can't seem to see >what I'm doing wrong. Maybe one of you can tell me: > qsort(&t[0], 2, sizeof(struct tstr), (*compar)()); Hmm... It seems to me you have a couple of things confused... 1. The qsort 'compar' argument is a pointer to a function, thus you send it a pointer to a function (you seem to have put the declaration in the parameter list). 2. You are really sending qsort(3) an integer in that field, since compar() returns an integer. Not only that but you are calling compar in the parameter list with no parameters (thus you believe compar is getting bogus arguments, which it is since you aren't sending any...). The correct statement would be something like: qsort((char *)&t[0], 2, sizeof(struct tstr), compar); which will send the ADDRESS of compar() and not the value the function returns. Hope this helps.... eric -- | Eric Herrin II cbosgd!ukma!eric | | "'tis better to be silent eric@UKMA.BITNET | | and be THOUGHT a fool, than to open eric@ms.uky.csnet | | one's mouth and remove all doubt." eric@ms.ukFrom: Juam Oct