initialization of automatic structures/unions

Paul Stachour stachour at sctc.com
Sat Mar 2 11:02:47 AEST 1991


filisa at 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 at sctc.com      1210 W. County Rd E, Suite 100           
		 	   Arden Hills, MN  55112
                             [1]-(612) 482-7467



More information about the Comp.lang.c mailing list