Generic pointers
Chris Torek
chris at umcp-cs.UUCP
Wed Oct 29 08:44:32 AEST 1986
In article <7800017 at datacube> stephen at datacube.UUCP writes:
>I generally use or define caddr_t as the type of a generic pointer, and then
>use macros to perform the indicated operations, i.e.:
>
>caddr_t generic_pointer;
>
>#define DATA( p, type ) (*((type *)(p)))
>#define SUCC( p, type ) ((p) += sizeof(type))
>
>a = DATA(p,int);
>SUCC(a, int);
>b = DATA(p,double);
>SUCC(p, double);
Or, if you want the effect of *(type *)(p)++:
#define ACCESS(p, type) ((p) += sizeof (type), (type *)(p)[-1])
a = ACCESS(p, int);
b = ACCESS(p, double);
Note that any such mangling of pointer types is inherently machine
dependent. You can reduce the dependency, but not eliminate it.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list