🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9669

Re: Generic pointers

#9669
From: Chris Torek
Date: Tue, 28 Oct 1986 22:44
27 lines
1394 bytes
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
Technical Details
Message-ID: <4039@umcp-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!chris
References: <4763@brl-smoke.ARPA> <7800017@datacube>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!chris
From: chris@umcp-cs.UUCP (Chris Torek)
Newsgroups: net.lang.c
Subject: Re: Generic pointers
Message-ID: <4039@umcp-cs.UUCP>
Date: Tue, 28-Oct-86 17:44:32 EST
Article-I.D.: umcp-cs.4039
Posted: Tue Oct 28 17:44:32 1986
Date-Received: Tue, 28-Oct-86 23:27:01 EST
References: <4763@brl-smoke.ARPA> <7800017@datacube>
Reply-To: chris@umcp-cs.UUCP (Chris Torek)
Organization: University of Maryland, Dept. of Computer Sci.
Lines: 27