Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!uunet!dg!fs06!pds From: pds@lemming.webo.dg.com (Paul D. Smith) Newsgroups: comp.lang.c Subject: Re: union or type casting, which to use? Message-ID: Date: 30 Nov 90 14:45:46 GMT References: <9011271554.AA23331@bisco.kodak.COM> <28080@mimsy.umd.edu> Sender: root@dg.dg.com Organization: NSDD/ONAD, Data General Corp., Westboro, MA Lines: 36 In-reply-to: chris@mimsy.umd.edu's message of 29 Nov 90 08:32:38 GMT [] In article [] pds@lemming.webo.dg.com (Paul D. Smith) writes: [] >In your case, you have no problem: the union elements are both the [] >same size and are guaranteed by ANSI to be compatible -->with [] >a cast<--: [] >both are pointers. [details deleted, see original article] [] Are you certain? [proof deleted, see original article] Hmm. I see your point here. I retract my statement about "guaranteed by ANSI". It would appear that there really is no truly portable way to initialize unions of any reasonable complexity; if you don't want to use the first element of the union then you are SOL (unless you are making a union where all elements have the same type structure, which could be useful in some applications). Of course, I'd venture to say that the static initialization I posted would work on 99% of machines available today; does *anyone* know of a machine which uses different internal representations of pointers for different structure types? Also of course, it's always that last 1% which is the kick in the pants :-) Bummer. Too bad ANSI couldn't come up with some more syntax for initializing unions ... (yes I know it would be difficult and not very compatible, and no I don't have any good ideas offhand, and I'm not criticizing them, just thinking wistfully ... ) -- paul ----- ------------------------------------------------------------------ | Paul D. Smith | pds@lemming.webo.dg.com | | Data General Corp. | | | Network Services Development Division | "Pretty Damn S..." | | Open Network Systems Development | | ------------------------------------------------------------------ Brought to you by Super Global Mega Corp .com