char* vs void*
Robert Jacobs
bobj at glinj.gli.com
Thu Jan 3 04:14:29 AEST 1991
>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 at gli.com |
More information about the Comp.lang.c
mailing list