Xref: utzoo comp.lang.c++:10966 comp.lang.c:34998 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!glinj.gli.com!bobj From: bobj@glinj.gli.com (Robert Jacobs) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: char* vs void* Keywords: char* vs void* pointer arithmitic Message-ID: <1991Jan2.171429.11566@glinj.gli.com> Date: 2 Jan 91 17:14:29 GMT References: <11745@alice.att.com> <2778A795.6E71@tct.uucp> <17590@paperboy.OSF.ORG> <277BAC53.F2A@tct.uucp> Organization: General Logistics International, Inc. Lines: 33 >Pointers of types |char *| and |void *| must both be able to hold the >address of any object. The reason why this is so differs for the two >types. For |char *| it's existing practice, and for |void *| it's the >decree of ANSI. >When ANSI invented |void *|, they made it capable of holding any >pointer. Since |void *| can hold any pointer, and |char *| can hold >any pointer, there would be no point (:-)) in an implementation giving >them different representations. So ANSI went that final step and >_required_ that their representations be identical. >>Do you mean "can be converted to each other and back without loss of >>information?" >Yes, and that's the important point for this discussion. A portable >qsort() can cast its |void *| array parameter to |char *| to do >pointer arithmetic, then cast the results of the pointer arithmetic >back to |void *| to generate the comparison function's arguments. What I can't understand is that ANSI decided that one cannot do pointer arithmitic on a void*, like a char*. Because of this, new work is forced to use char* as the generic pointer that can do pointer arithmitic. This continues the existing practice that char* is special. Void* should be allowed to do pointer arithmitic so that char* does not have to be used for new work. But I guess my opinion is too late to be in any version of ANSI C or C++. Too bad. Robert Jacobs | General Logistics International Inc. | bobj@gli.com |