Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Comparison functions for qsort() and bsearch() Keywords: Sun, C++ Message-ID: <70271@microsoft.UUCP> Date: 28 Jan 91 21:32:08 GMT References: <1990Dec26.160636.15566@clear.com> <1991Jan6.050801.20821@cbnewsk.att.com> <1991Jan9.161633.21922@clear.com> <1991Jan21.022720.20707@cbnewsk.att.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 20 In article <1991Jan21.022720.20707@cbnewsk.att.com> hansen@pegasus.att.com (Tony L. Hansen) writes: >I'll repeat: The key to all of this is that whenever calling qsort(), you >always have to pass it a function which casts from the const void* back to >the true pointer that was passed in. And once you do that, you can then cast >to any base pointer you want! I don't doubt that this should work on just about any sane compiler out there today, _but_ I see nothing in ARM that gives one permission to explicitly cast back from a void* back to the original object* type. What C++ does permit is casting back from a pointer to a smaller object. I don't see anywhere ARM defines that the effective size of a void object, were such allowed to exist, is smaller than any "real" object. However, most all systems would make a char the smallest object, so one _should_ be able to cast to/from a char*. Thus, I claim if one needs a generic object pointer, one should use a char*, not a void*. If you want to represent a generic address, but not imply an object is referred to, then feel free to use a void*. Since section 5.4 does not explicitly allow casting back from a void*, but most all compilers allow it, I claim a cast back from void* is an un-constrained error -- IE a programming error compilers are not required to diagnose.