unions or void * to transmit "generic" pointers

Wade Guthrie evil at arcturus.UUCP
Wed Sep 13 04:04:01 AEST 1989


I'm curious about whether it is okay to use a void * to transmit pointers
between functions (when the func's agree on the type, but the at least one
of the functions needs to be able to handle all sorts of DATA pointers) or
whether it is more correct/portable to use unions of pointers.  

Specifically, I want to do something like:

Routine()
{
	sometype *stuff; /* a pointer to where to put the data */

	. . .

	/* this routine needs to ask the user for some data, so it
	 * will call a menu routine
	 */

	Menu( (void *) stuff, type);
}

Menu(point, type)
void * point;
int type;
{
	. . .
	switch(type)
	{
	case SOMETYPE:
		*((sometype *) point) = /* something appropriate */

	. . .
}

So, do I pass a union of pointers (seems pretty cumbersome) instead, or can 
I do the above?


Wade Guthrie
evil at arcturus.UUCP
Rockwell International
Anaheim, CA

(Rockwell doesn't necessarily believe / stand by what I'm saying; how could
they when *I* don't even know what I'm talking about???)



More information about the Comp.lang.c mailing list