Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!timbuk!juniper09!ds From: ds@juniper09.cray.com (David Sielaff) Newsgroups: comp.lang.c Subject: Re: Expressions in initializers Message-ID: <205653.3418@timbuk.cray.com> Date: 5 Mar 91 03:38:34 GMT References: <17270@crdgw1.crd.ge.com> <760@ajpo.sei.cmu.edu> <1991Mar4.144939.8311@ux1.cso.uiuc.edu> <17294@crdgw1.crd.ge.com> <10592@dog.ee.lbl.gov> Organization: Cray Research, Inc., Eagan, MN Lines: 36 In article <10592@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes: >In article <17294@crdgw1.crd.ge.com> volpe@camelback.crd.ge.com >(Christopher R Volpe) writes: >>"The square root of two" can be evaluated at compile time, but "sqrt(2.0)" >>is an invocation of a function. How is the compiler supposed to know >>what sqrt is? I could have in another file: >> >>double sqrt(double x) >>{ >> return x - 1.0; >>} > >Not in ANSI C (at least, not if you `#include '; I am not sure >about the case where you do not include the standard header). Compilers >can of course define their own languages and allow > > static double root2 = sqrt(2.0); > >but someone writing ANSI C should assume neither this nor that writing > > double sqrt(double x) { return x - 1.0; } > >will work. >-- >In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) >Berkeley, CA Domain: torek@ee.lbl.gov According to ANSI C, it is not necessary to `#include ' to have this effect. Identifiers such as `sqrt' are always reserved as identifiers with external linkage. Thus you could define a new `sqrt' as a static function in a compilation unit, but if `sqrt' ends up with external linkage, the compiler can assume that it means the library function. Dave Sielaff Cray Research