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

Stephen Clamage steve at taumet.com
Fri Apr 26 04:04:33 AEST 1991


vic at grep.co.uk (Victor Gavin) writes:

>... 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.]]

>Could anyone tell me whether the ANSI committee pondered over the problem of
>tidying up the inconsistencies of the C initializations ?

IMHO, this is not an inconsistency.  There is no way to specify an
anonymous aggregate constant in C.  Further, if we accept the syntax you
show, it would have to try to assign the aggregate constant to a pointer,
which would be rejected in any case.
You would need something more like this:
	struct fred { struct bert *abc; } blip = { &{1,1} };
This has some problems, in that {1, 1} has no type.

Bracketed initializers are syntactic ways to supply values to members
of the aggregate being initialized.  "{1,1}" has no meaning on its own.
You would need to extend the C language to support anonymous aggregate
constants, perhaps along the lines of
	(struct bert){1, 1}
(This is not a recommendation.)

I don't know whether X3J11 ever discussed such a thing, but I'm sure
they would have considered it outside their purview, there being no
such existing practice.

BTW, if one struct is "bert", shouldn't the other be "ernie"?
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list