Structure Pointer Question

chris at mimsy.UUCP chris at mimsy.UUCP
Tue Jul 12 23:50:12 AEST 1988


In article <2080 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:
>Keywords: You don't really *read* this line, do you?

(Some do!)

>  typedef union {
>		   THIS_TYPE_OF_OBJECT   *this.id;
>		   THAT_TYPE_OF_OBJECT   *that.id;
>		   ANOTHER_TYPE_OBJECT   *another.id;
>                }
>		   OBJECT_UNION;
>
>  Where, of course, THIS_TYPE_OF_OBJECT, THAT_TYPE_OF_OBJECT, etc. are
>all typedefs of structures.

This is what `void *' is for (and if you do not have `void *', `char *'
*probably* works):

	struct object {
		int	type;
		...
		void	*pointer;
	}; ...
		struct some_real_object *p = this_obj->pointer;
		p->real_data = ...;

Without `void *' this must be cast:

		struct some_real_object *p =
		    (struct some_real_object *)this_obj->pointer;
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list