Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!venera.isi.edu!lmiller From: lmiller@venera.isi.edu (Larry Miller) Newsgroups: comp.lang.c Subject: Re: Function-types: compatability, and typedefs Message-ID: <9488@venera.isi.edu> Date: 1 Sep 89 18:14:54 GMT References: <19361@mimsy.UUCP> Reply-To: lmiller@venera.isi.edu.UUCP (Larry Miller) Distribution: comp Organization: Information Sciences Institute, Univ. of So. California Lines: 37 In article <19361@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: > >Given a pointer whose type is , >you can always (by the proposed standard, at least) cast it to some >other function pointer type () and then >back, and the result (after casting back) will act the same as the >original. Normally, however, you have to use that `cast-back' to force >it to work. In this particular case, however, the two types are > > int (*)(void *, void *) [qsort compare function] >and int (*)(char *, char *) [strcmp] > >and `void *' and `char *' are required to be `the same' in >representation, since historically `char *' has been used where the >pANS uses `void *'. (In fact, in Classic C, qsort's fourth argument >has the second type above, not the first.) In order not to break such >code, the pANS has a constraint that is supposed to make those two >function-pointer types interchangeable. This is my interpretation also, but GNU, in particular, disallows this. Since my copy of the draft standard is very old (Nov, 1985), could someone refer to a specific section in the latest draft? Also, it's my interpretation that in a function taking a (void *), that this would work, without cast, for anything *. Specifically, qsort: void qsort(void *base, size_t n, size_t width, int (*f)(const void *, const void *)); Can be passed a char ** as the first element WITHOUT specifically casting to void * (as long as the prototype is in scope). Larry Miller lmiller@venera.isi.edu (no uucp) USC/ISI 213-822-1511 4676 Admiralty Way Marina del Rey, CA. 90292