Operations on pointers to void.

D'Arcy J.M. Cain darcy at druid.uucp
Thu Aug 16 11:49:47 AEST 1990


In article <174 at srchtec.UUCP> johnb at srchtec.UUCP (John Baldwin) writes:
>In article <1990Aug12.231202.23826 at druid.uucp> darcy at druid.uucp
>  (D'Arcy J.M. Cain) writes:
>>know that the data can be any type but we want to treat it as bytes.  Perhaps
>>we need a new type which acts like void * but allows pointer arithmetic based
>>on the smallest data type supported by the system, usually (but not always)
>>a byte.
>
>There is a simple fix to this: you can operate on void pointers by casting
>them to a useful type.  For example, perhaps you are writing a function foo()

I understand how to cast.  All I am saying is that it shouldn't be necessary.
I find casts to be clumsy and try to avoid them wherever I can.  I think
it is better to define your functions and data types so that any conversion
is automatically done by the compiler.  If the language supported pointer
arithmetic on void * (or supplied another data type with the same features)
this would be possible.  Note that GNU C does support it and I can't see any
harm in it.  ANSI code that doesn't know about it runs just fine but if you
use the feature you do no harm either.

So can anyone suggest any reason why supporting this feature would break
code or otherwise be a problem.  Of course code which used this feature
would be unportable but what other problems would this cause?

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list