Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!shelby!msi.umn.edu!sctc.com!stachour From: stachour@sctc.com (Paul Stachour) Newsgroups: comp.lang.c Subject: Re: initialization of automatic structures/unions Message-ID: <1991Mar2.000247.11318@sctc.com> Date: 2 Mar 91 00:02:47 GMT References: <13599@life.ai.mit.edu> Organization: SCTC Lines: 35 filisa@albert.ai.mit.edu (Filisa Vistima) writes: >If such a construct such as this is illegal (says my compiler): > struct Stuff { int i, j, k, l; }; > int main(argc, char ** argv) { > struct Stuff stuffy = { 0, 0, 0, 0 }; /* illegal part */ > } >Can someone give me a good reason why initializing automatic >structures/unions is illegal? Because according to the rules of initialization: Initializers follow the sames rules for type and conversion as do assignment statements, and one can't assign "constant structures" or "constant arrays" in C. If C followed the "rule of least asstonishment" (which it does not), then the operations of: Assignment Initialization Comparison would be "equivalent" in what one could compare, assign, and initialize. But C has NEVER understood this principle. I recommend you use a programming language like Ada, which was designed for software engineering. Then you will have many fewer of the "why is this incosistant with that" kind of questions. ...Paul -- Paul Stachour Secure Computing Technology Corp stachour@sctc.com 1210 W. County Rd E, Suite 100 Arden Hills, MN 55112 [1]-(612) 482-7467