Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!tcdcs!tcdmath!ch From: ch@maths.tcd.ie (Charles Bryant) Newsgroups: comp.lang.c Subject: Re: Union initialization Summary: casts Message-ID: <609@maths.tcd.ie> Date: 24 Feb 89 21:09:31 GMT References: <816@atanasoff.cs.iastate.edu> <16019@mimsy.UUCP> <51116@yale-celray.yale.UUCP> Reply-To: ch@maths.tcd.ie (Charles Bryant) Organization: Maths Dept., Trinity College, Dublin Lines: 35 In article <51116@yale-celray.yale.UUCP> wald-david@CS.YALE.EDU (david wald) writes: >In article <16019@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>In article <816@atanasoff.cs.iastate.edu> hascall@atanasoff.cs.iastate.edu >>(John Hascall) writes: >>>Does 'ANSI' C allow for union initialization? >> . . . >Any suggestions? Given: If a union has two members with the same type, the compiler need not distinguish between them. How about: union { float f; double d; int i; char c; } foo = { 1 }; /* initialises i */ OR } foo = { (float) 1.1 }; /* f */ OR } foo = {(double) 1.1 }; /* d */ OR } foo = { (char) 'a'}; /* c */ Perhaps this would be too much of a special case for the compiler (it otherwise dosen't need to know that an expression is of type 'char' for instance). -- Charles Bryant. Working at Datacode Electronics Ltd.