Path: utzoo!mnetor!tmsoft!torsqnt!hybrid!scifi!bywater!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: initializing to expressions Message-ID: <598@taumet.com> Date: 9 Feb 91 18:16:46 GMT References: <91039.144030BRL102@psuvm.psu.edu> Organization: Taumetric Corporation, San Diego Lines: 20 BRL102@psuvm.psu.edu (Ben Liblit) writes: >I want to initialize an array [statically] with values that are constant, >but are in the form of expressions. For example, > double value[ 2 ] = { sqrt( 2 ) / 2, cos ( sqrt( 5 ) ) }; >Is there any way to accomplish this? In C, static initializers may not contain function calls. sqrt and cos are part of the run-time library, not built-in to the language. C++, however, allows general expressions to initialize static variables. The compiler collects non-constant expressions into a compiler-generated initialization routine, then calls the routine before any user code in the main program. This is in fact run-time, rather than compile-time, initialization, but it allows the convenient notation you want. -- Steve Clamage, TauMetric Corp, steve@taumet.com