Expressions in initializers
David Sielaff
ds at juniper09.cray.com
Tue Mar 5 13:38:34 AEST 1991
In article <10592 at dog.ee.lbl.gov> torek at elf.ee.lbl.gov (Chris Torek) writes:
>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
According to ANSI C, it is not necessary to `#include <math.h>' 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
More information about the Comp.lang.c
mailing list