Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!usenet From: mcdonald@aries.scs.uiuc.edu (Doug McDonald) Newsgroups: comp.lang.c Subject: Re: Expressions in initializers Message-ID: <1991Mar4.144939.8311@ux1.cso.uiuc.edu> Date: 4 Mar 91 13:33:25 GMT References: <17270@crdgw1.crd.ge.com> <760@ajpo.sei.cmu.edu> Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 30 In article <17270@crdgw1.crd.ge.com> volpe@camelback.crd.ge.com (Christopher R Volpe) writes: >In article <760@ajpo.sei.cmu.edu>, rabbieh@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