Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: unions or automatic aggregates cannot be initialized. Why? Message-ID: <1990Jan1.003013.24864@utzoo.uucp> Organization: U of Toronto Zoology References: <915@mbf.UUCP> Date: Mon, 1 Jan 90 00:30:13 GMT In article <915@mbf.UUCP> kris@mbf.UUCP (A. Krishna Murthy) writes: > In the definitive text 'The C Programming Language' by > Brian W kernighan and Dennis M Ritchie... > "It is not permitted to inititalize unions or automatic aggregates." > Why? The new definitive text is the 2nd edition of K&R, which documents recent changes to this rule. Speaking strictly of the old rule, however... The problem with initializing unions is deciding which member is to be initialized. You can't do it by looking at the type of the initializer; it is easy to construct cases where this is ambiguous. One has to invent some new notation to pick the member. Dennis never quite got around to it. (The new rule is that initializers apply to the first member, always. This is more a matter of giving unions a well-defined initial value than of providing a useful way to initialize them, obviously.) The problem with automatic aggregate initialization was that it's an implementation nuisance. Initialization of static aggregates just requires setting up the memory to be in that state initially, while initializing automatic aggregates requires generating code to do the work at run time. (Automatic aggregate initialization is now permitted, subject to some small restrictions.) -- 1972: Saturn V #15 flight-ready| Henry Spencer at U of Toronto Zoology 1989: birds nesting in engines | uunet!attcan!utzoo!henry henry@zoo.toronto.edu