initializing to expressions

David Ebbo dsebbo at dahlia.uwaterloo.ca
Mon Feb 11 11:55:18 AEST 1991


In article <91039.144030BRL102 at psuvm.psu.edu> BRL102 at psuvm.psu.edu (Ben Liblit) writes:
>I want to initialize an array 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?  I know I could do this in some sort of
>'for' loop, or else by assigning values explicitly.  I'd really like to avoid
>this, though, as having the initialization in the declaration area would be much
>more readable.  The example above is a simplification -- the actual arrays are
>quite large and explicit, individual assignment would be too cluttering.
>
>Is there *any* way to convince my compiler (High C Compiler version 2, off of a
>Unix box) to give me this sort of initialization within the declaration area?
>

I think that the answer is no.  To be able to use initialization, the values
have to be known at compile time, which is not the case if you are calling
functions.

Why don't you compute the values 'by hand' first, and then put them all in a
header file of #define statements?  Well, if you have a lot of them,  it might
not be a great idea :-)




More information about the Comp.lang.c mailing list