Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Union initialization Message-ID: <16019@mimsy.UUCP> Date: 18 Feb 89 16:20:38 GMT References: <816@atanasoff.cs.iastate.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 25 In article <816@atanasoff.cs.iastate.edu> hascall@atanasoff.cs.iastate.edu (John Hascall) writes: >Does 'ANSI' C allow for union initialization? Because all static and global variables are initialised to 0 (cast to the appropriate type), the pANS *must* allow for union initialisation, else how could one talk about the initial value of a static or global union? But since members of a union may overlay one another, and a 0 of one type may not match a zero of another, there must be some rule for deciding *which* union member(s) are to be zero. The rule is (perhaps overly) simple: the first member of the union is initialised. Given union { float f; int i; } u; u.f is 0.0, and u.i is indeterminte. You may write union { float f; int i; } u = { 1.0 }; to set u.f, but you cannot initialise u.i since it is not the first member. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris