c types problem

Frank Adams franka at mmintl.UUCP
Wed Jan 8 02:04:07 AEST 1986

In article <1261 at brl-tgr.ARPA> gwyn at brl-tgr.ARPA (Doug Gwyn <gwyn>) writes:
>> 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.

I got the impression he wanted long, short, etc. in his union, as well as
pointers.  If so, I don't think (void *) is portable; a long is bigger than
any pointer on some machines.

Frank Adams                           ihpn4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108

More information about the Comp.lang.c mailing list