Why didn't ANSI make initialisation consistent ????

Jack Morrison jackm at agcsun.UUCP
Fri Apr 26 07:15:49 AEST 1991


In article <1991Apr24.141206.18103 at grep.co.uk> vic at grep.co.uk (Victor Gavin) writes:
>I (after many, many years of C programming) found that I couldn't perform what
>I considered to be a reasonable assignment command.
>I traced it back to my use of
>	char *fred = "bert"
>being the same as
>	char fred[] = {'b', 'e', 'r', 't', '\0'}

We'll assume ;-) you really meant that it's similar to

	char _fred[] = {'b', 'e', 'r', 't', '\0'};
	char *fred = _fred;

>Which made me believe that I could use the following code:
>	struct bert { int a, b; }
>	struct fred { struct bert *abc; } blip = { {1,1} };
>
>[[ie That the compiler will place the data for the structure into one of the
>data segments and then place it's address into the pointer variable.]]
>Of course none of my compilers liked this.

It's not so much an *initialization* inconsistency, but the limitation that
you can't write a constant structure value the same way you can a constant
string. For example, it would also be nice to be able to call

	void foo(struct bert b);

[NOT "struct bert *b", mind you] as

	foo( {1,1} );

or, if the compiler would like a little more help, 

	foo( (struct bert){1,1} );

I have no answer as to whether anyone official has considered it before...

-- 
"How am I typing?  Call 1-303-279-1300"     Jack C. Morrison
Ampex Video Systems    581 Conference Place, Golden CO 80401



More information about the Comp.lang.c mailing list