Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: JONESD@kcgl1.eng.ohio-state.edu (David Jones)
Subject: Re: Qsort problem in DEC C
Date: 3 Feb 1995 18:59:49 GMT	[thread overview]
Message-ID: <3gtuf5$i1u@charm.magnus.acs.ohio-state.edu> (raw)
In-Reply-To: lloyd-dr-0302950907550001@149.252.239.58

In article <lloyd-dr-0302950907550001@149.252.239.58>,
  lloyd-dr@nlvvax.llnl.egg.nv.doe.gov (David Lloyd) writes:
> All right, I've apparently gone brain-dead, but I cannot for the life of me
>get the following C example to compile with DEC C 4.0 under OpenVMS/VAX V6.1.
> I get the warning message (between the dashed lines) that says (to me anyway)
>"a" is not compatible with "a". Can anyone tell me where my programming and/or
>linguistic skills left the room (with my sanity not far behind)?
>
>/* Program that does no useful work */
>
>#include <stdlib.h>
>
>int compare (int *a, int *b)
>{
>  if (a < b) return(-1);
>  if (a == b) return(0);
>  if (a > b) return(1);
>}
>
>void main(int argc, char** argv)
>{
>
>  int intarray[10] = {4,3,6,2,1,7,9,8,3,1};
>
>  qsort(intarray, 10, sizeof(int), compare);
>
>  return;
>}


The stdlib header file defines the last argument to qsort as a pointer
to a funtion that take arguments (const void *, const void *).  The
compiler complains because you are passing a function with arguments
(int *, int *).

One workaround is to add the declaration "int compare();" to your main()
function, the old fashioned function declaration disables the type checking
on the arguments.

BTW, the compare() routine in your sample is going to compare the addresses
of the data items, not the values.


David L. Jones               |      Phone:    (614) 292-6929
Ohio State Unviversity       |      Internet:
2070 Neil Ave. Rm. 122       |               jonesd@kcgl1.eng.ohio-state.edu
Columbus, OH 43210           |               vman+@osu.edu

Disclaimer: Dogs can't tell it's not bacon.


  reply	other threads:[~1995-02-03 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-02-03 17:05 Qsort problem in DEC C David Lloyd
1995-02-03 18:59 ` David Jones [this message]
1995-02-03 19:33 ` John Buehler
1995-02-06 23:14 ` Alan Rollow - Dr. File System's Home for Wayward Inodes.
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox