Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!gatech!mcnc!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Function-types: compatability, and typedefs Message-ID: <14511@haddock.ima.isc.com> Date: 4 Sep 89 18:49:01 GMT References: <19361@mimsy.UUCP> <1989Sep1.113440.28300@jarvis.csri.toronto.edu> <1999@munnari.oz.au> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 20 ok@cs.mu.oz.au (Richard O'Keefe) writes: >flaps@dgp.toronto.edu (Alan J Rosenthal) writes: >>ok@cs.mu.oz.au (Richard O'Keefe) writes: >>>int cmp(char **s1, char **s2) { return strcmp(*s1, *s2); } > >>Actually, you should write >>int cmp(void *s1, void *s2) { return(strcmp(*(char **)s1, *(char **)s2)); } > >Sorry; I was working from an old [pre-ANSI] manual with char *base and so on. That's not the reason for the correction. The correct pre-ANSI code couldn't use "void *" or a prototype, but you'd still have to declare the arguments to be generic ("char *") and then cast them to "char **". This isn't just a quibble. There are many real machines out there that have more than one pointer format. The code will fail in mysterious ways if you don't declare the formal arguments to be the same type as the actuals. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ("But I tried it on my VAX, and it worked, so it must be right!")