Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Problem initializing a structure Message-ID: <1988Dec18.004701.27063@utzoo.uucp> Organization: U of Toronto Zoology References: <154@cjsa.WA.COM> Date: Sun, 18 Dec 88 00:47:01 GMT In article <154@cjsa.WA.COM> jeff@cjsa.WA.COM (Jeffery Small) writes: >static char *menu[] = { "aaa", "bbb", "ccc", 0 }; > >Now, what I actually want to do is to assign the value to X.item in the >initialization statement rather than the assignment statement. So I make >the following change to the program: > >TEST X = { menu, *menu }; > >but when I attempt to compile this I get: >> "z.c", line 10: illegal initialization >...why doesn't this initialization work... In the general case, the '*' operator cannot be executed at compile time, so it is illegal in compile-time initializers. In this specific case, a smart compiler could actually compile it, but it is thought desirable to define whether something is legal C without reference to how smart the compiler is. The best you could do would be to define a separate variable to hold "aaa" and point to it from both menu and X. This is admittedly inconvenient, but anyone wanting to initialize complex interlinked structures at compile time in C had better get used to inconvenience. -- "God willing, we will return." | Henry Spencer at U of Toronto Zoology -Eugene Cernan, the Moon, 1972 | uunet!attcan!utzoo!henry henry@zoo.toronto.edu