Expressions in initializers
Chris Torek
torek at elf.ee.lbl.gov
Tue Mar 5 11:03:16 AEST 1991
In article <17294 at crdgw1.crd.ge.com> volpe at 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 <math.h>'; 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 at ee.lbl.gov
More information about the Comp.lang.c
mailing list