c types problem

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Mon Jan 6 20:45:49 AEST 1986


> I need to define a type for a program which can store any of the types
> long, int, short and also the unsigned variants of them.
> Some of the routines referencing this types will not use them directly
> however, it will use the sys/types.h typedefs dev_t, time_t etc.
> It will look something like this: "(*func)(&data)" there *func,
> but not the calling routine knows what type is currently stored in "data".
> The formal (but ugly) way to solve this would proparbly be to use a union
> for all (about 10) types. But now I wonder if anyone have a simpler but
> resonably portable solution?

Since you're going to pass pointers, just coerce the actual data
address into a generic pointer ((void *) if you have it, otherwise
(char *)) and coerce it back inside the called function.



More information about the Comp.lang.c mailing list