[net.lang.c] Generic pointers

chris@umcp-cs.UUCP (Chris Torek) (10/29/86)

In article <7800017@datacube> stephen@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@umcp-cs		ARPA:	chris@mimsy.umd.edu