Expressions in initializers

Doug McDonald mcdonald at aries.scs.uiuc.edu
Mon Mar 4 23:33:25 AEST 1991


In article <17270 at crdgw1.crd.ge.com> volpe at camelback.crd.ge.com (Christopher R Volpe) writes:
>In article <760 at ajpo.sei.cmu.edu>, rabbieh at ajpo.sei.cmu.edu (Harold
>Rabbie) writes:
>|>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.
>
>Read it again. You have it almost backwards.
>
>|>
>|>e.g. I can say:
>|>
>|>static double x = sqrt( 2.0 );
>
>No you can't.
>
>
>Statics are initialized at compile time, therefore they can't be initialized
>by an expression that can be evaluated only at runtime.
>                         


sqrt(2.0) is an expression. It CAN be evaluated at compile time. Perhaps
some people don't want to write compilers that do that (i.e. they are too
lazy), but it most certainly CAN be evaluated.

Perhaps a different explanation is appropriate?

Doug McDonald



More information about the Comp.lang.c mailing list