Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!decvax!ucbvax!ucdavis!lll-crg!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: c types problem Message-ID: <1261@brl-tgr.ARPA> Date: Mon, 6-Jan-86 05:45:49 EST Article-I.D.: brl-tgr.1261 Posted: Mon Jan 6 05:45:49 1986 Date-Received: Tue, 7-Jan-86 06:33:17 EST References: <870@kuling.UUCP> Organization: Ballistic Research Lab Lines: 13 > 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.