Operations on pointers to void.

John Baldwin johnb at srchtec.UUCP
Wed Aug 15 07:40:57 AEST 1990


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()
which can take a pointer to anything, and for some (unspecified) reason,
you want to "bump" the pointer up three bytes....

SOMETYPE   foo( void *myptr, size_t someval, ... )
{
      .
      .

   *((char *)&myptr) += 3;

      .
      .
}
-- 
John T. Baldwin                      |  johnb at srchtec.uucp
Search Technology, Inc.              |  johnb%srchtec.uucp at mathcs.emory.edu
standard disclaimer:                 |  ...uunet!samsung!emory!stiatl!srchtec..
opinions and mistakes purely my own. |  ...mailrus!gatech!stiatl!srchtec...



More information about the Comp.lang.c mailing list