Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c Subject: Re: How to initialize unions Message-ID: <660030@hpclscu.HP.COM> Date: 5 Apr 89 22:01:18 GMT References: <3742@phri.UUCP> Organization: Hewlett-Packard Calif. Language Lab Lines: 33 > > 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 And don't forget to brace-enclose the initializer of the union member, as follows: struct ident stuff = { { "abcd", KEYWORD, {KW_ABCD}}, /* ^^^^^^^^^^^ */ /* ... */ }; --- Shankar