Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sdcc3.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcc3!38613457 From: 38613457@sdcc3.UUCP (38613457) Newsgroups: net.lang.c Subject: Initializing unions, here and now. Message-ID: <2427@sdcc3.UUCP> Date: Tue, 30-Oct-84 23:32:56 EST Article-I.D.: sdcc3.2427 Posted: Tue Oct 30 23:32:56 1984 Date-Received: Thu, 1-Nov-84 05:36:42 EST Distribution: net Organization: U.C. San Diego, Computer Center Lines: 46 fig() I here a lot about initializing unions, this is a pointer to a union, but the space it points to is big enough for aything that you should be able to put into it. Good, Bad, any better in the here now where I can play with them? As to ANSI, I would be happy if the compiler would cram whatever I choose to initialize into a space big enough to use for any of the members and position it for the type that it is. If the requires specific typecasting then ok, but here and now does anyone have something which looks better. Jim sdcsvax!sdcc6!ix269 {the 38613457 should be -$185 by oct 31 ) --------------------- mangle this line ------------------- #include union Val { int oi; char oc; double od; }; typedef double BIG; tmpchar[sizeof(BIG)] = 'A'; struct Onion { int valtyp; union Val *val; } onion[] = { 1, (union Val *) tmpchar }; main() { extern Onion onion[]; printf("1, val = %c\n",onion->val->oc); onion->val->od = 3.1415927; printf("2, val = %lf\n",onion->val->od); onion->val->oi = 1; printf("3, val = %d\n",onion->val->oi); } /* eot */