Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mmintl.UUCP Path: utzoo!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.lang.c Subject: Re: c types problem Message-ID: <1008@mmintl.UUCP> Date: Tue, 7-Jan-86 11:04:07 EST Article-I.D.: mmintl.1008 Posted: Tue Jan 7 11:04:07 1986 Date-Received: Sat, 11-Jan-86 06:00:20 EST References: <870@kuling.UUCP> <1261@brl-tgr.ARPA> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 21 In article <1261@brl-tgr.ARPA> gwyn@brl-tgr.ARPA (Doug 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