home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!portal!dfuller
- From: dfuller@portal.hq.videocart.com (Dave Fuller)
- Subject: Re: Help. (Unix C)
- Message-ID: <Bx8Cw8.5tB@portal.hq.videocart.com>
- Organization: VideOcart Inc.
- X-Newsreader: Tin 1.1 PL3
- References: <2214@sdrc.COM>
- Date: Thu, 5 Nov 1992 06:33:44 GMT
- Lines: 28
-
- scjones@thor.sdrc.com (Larry Jones) writes:
- : An ANSI compiler will, quite properly, object to this code -- it is
- : neither correct nor portable. The comparison function *must* be
- : defined with two "void *" arguments (or "char *" if your compiler is
- : too old to support "void *"); that's what qsort calls it with. Some
- : implementations use the same representation for all pointer types and
- : on those implementations you can misdefine the function and it will
- : work, but this is not guaranteed and there are systems where it will
- : fail.
- :
- First of all, i don't use an ANSI compiler except for about 20%
- of my code (the declaration of the function should have helped on that).
- But, even on an ANSI compiler this will work. void is used to take on
- no predetermined meaning, or to actually mean return NOTHING from a
- function if used as a declaration type. malloc returns void *, but it
- won't complain if you dont cast the return value and assign it to a
- char *. Also, the strcmp() function is used QUITE OFTEN in qsort.
- look at the definition for it though strcmp(const char*,const char*)
- it doesn't have void * declared as you say a routine that qsort calls
- *must* have.
-
- And if the code were not portable, it compiles and works on a non-ansi
- compiler (and all of the ANSI ones i tried), so please take back the
- part where you say the code is not correct. it is.
-
- Dave fuller
- dfuller@portal.hq.videocart.com
-
-