home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!quads!pynq
- From: pynq@quads.uchicago.edu (George Jetson)
- Newsgroups: comp.lang.c
- Subject: Re: Problems with QSORT and function prototypes
- Message-ID: <1992Sep15.143458.21088@midway.uchicago.edu>
- Date: 15 Sep 92 14:34:58 GMT
- References: <1992Sep15.043445.3519@midway.uchicago.edu> <1992Sep15.123225.22760@blaze.cs.jhu.edu>
- Sender: news@uchinews.uchicago.edu (News System)
- Reply-To: pynq@midway.uchicago.edu
- Organization: D. J. Dougherty & Associates
- Lines: 38
-
- In article <1992Sep15.123225.22760@blaze.cs.jhu.edu> wilson@rhombus.cs.jhu.edu (Dwight Wilson) writes:
-
- >
- >qsort() is declared as:
- >
- >void qsort(void *base, size_t nmemb, size_t size,
- > int (*compar)(const void *, const void *));
- >
- >Your problem is being caused by the fourth argument, the comparison
- >function. qsort's declaration means that the comparison function
- >should take two (void *) parameters and return an int.
- >
- >Your functions expect two struct thing pointers or two int pointers.
- >You must rewrite them to take (void *) arguments (and cast them
- >internally).
-
- In fact, to get it past Borland C, I had to declare them as "const void *" -
- void * alone was not enough.
-
- Interestingly enough, the following hack worked as well:
- Declare:
-
- int (*fp)() = int_cmp;
-
- Then use fp, not int_cmp, in the call to qsort().
-
- I'm not sure which hack is less unattractive, but the fact that Borland
- treats this as an error, not merely a warning, seems a bit excessive to me.
-
- ************************************************************************
- A note to new readers: the weasely :-) symbol is frowned upon in this
- group. Any questions, see Phil Gustafson who will gladly rearrange your
- diodes for you.
- - From the AFU FAQ -
-
- - pynq@quads.uchicago.edu, who is still costing the net
- hundreds, if not thousands, of dollars, every time he posts -
- ************************************************************************
-