Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: How to initialize unions Message-ID: <16731@mimsy.UUCP> Date: 4 Apr 89 22:49:01 GMT References: <3742@phri.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 32 In article <3742@phri.UUCP> roy@phri.UUCP (Roy Smith) writes: >I've got a structure which looks like: > > struct ident { > char *name; > int type; > union { > double f; > int i; > } value; > }; > >and I want to initialize the name, type, and value.i elements of an array >of them them at compile time. Unless you have an extension, you cannot do this unless you change the order to union { int i; double f; } value; Even then, you must have a pANS-conformant compiler or its equivalent; most PCCs will refuse to initialise any unions, giving the error message >"operands of = have incompatible types" GCC should do the job, with the re-ordered union. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris