Expressions in initializers
Harold Rabbie
rabbieh at ajpo.sei.cmu.edu
Mon Mar 4 11:34:08 AEST 1991
Here's one for the comp.lang.c.lawyers - K&R 2 says (without explanation)
that non-constant expressions can be used as initializers only for static
scalars, not for automatics, and not for aggregates.
e.g. I can say:
static double x = sqrt( 2.0 );
but I can't say:
void foo( void )
{
double x = sqrt( 2.0 );
}
nor can I say:
static struct foo {
double x;
} bar = { sqrt( 2.0 ) };
What's the deal here - is ANSI easing up on those no-good implementers :-)
or is there a valid reason for this restriction?
P.S. No need to FAQ me over on this one.
More information about the Comp.lang.c
mailing list