Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.unix.wizards Subject: Re: Why doesn't this qsort example work? Message-ID: <6587@brl-smoke.ARPA> Date: Mon, 19-Oct-87 09:51:48 EDT Article-I.D.: brl-smok.6587 Posted: Mon Oct 19 09:51:48 1987 Date-Received: Tue, 20-Oct-87 02:33:02 EDT References: <7527@g.ms.uky.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 26 In article <7527@g.ms.uky.edu> sean@ms.uky.edu (Sean Casey) writes: !struct tstr { ! int a; ! int b; !}; !compar(x, y) !struct tstr *x, *y; char *X, *Y; /* replaces the above line */ !{ struct tstr *x = X, *y = Y; /* inserted new line */ ! if (x->a < y->a) /* coredumps here, therefore a or b is bogus */ ! return(-1); /* a < b */ ! if (x->a > y->a) ! return(1); /* a > b */ ! return(0); /* a = b */ !} !main() !{ ! struct tstr t[2]; ! t[0].a = 1; ! t[1].a = 2; ! /* this sorts t[] by the "a" field */ ! qsort(&t[0], 2, sizeof(struct tstr), (*compar)()); /* replace the above line with the following: */ qsort((char *)&t[0], (unsigned)2, sizeof(struct tstr), compar); !}