Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: Expressions in initializers Keywords: initializers Message-ID: <17270@crdgw1.crd.ge.com> Date: 4 Mar 91 13:33:25 GMT References: <760@ajpo.sei.cmu.edu> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 47 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. |> |>but I can't say: |> |>void foo( void ) |>{ |> double x = sqrt( 2.0 ); |>} Yes you can. |> |>nor can I say: |> |>static struct foo { |> double x; |>} bar = { sqrt( 2.0 ) }; That's correct. |> |>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. Statics are initialized at compile time, therefore they can't be initialized by an expression that can be evaluated only at runtime. ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com