Point me in the right direction

Guy Harris guy at auspex.UUCP
Sat Feb 18 19:50:53 AEST 1989


 >>double fund_consts[] = {
 >>	3.14159265,
 >>	2.7182818,
 >>	6.02E23,
 >>};
 >
 >   Of course, adding:
 >
 >     #define N_FCONSTS (sizeof(fund_consts)/sizeof(double)) 

So far, so good - this is an old C trick, which is quite useful, but may
not be known as well as it should be - but...

 >   then you can use stuff like:
 >
 >     extern fund_consts[N_FCONSTS];

(try "extern double fund_consts[...]"; that declaration makes it an
array of "int")

 >   elsewhere.

...only if "fund_consts" is *defined* in the same "elsewhere", or at
least declared with a size other than N_FCONSTS (since the value of the
expression "(sizeof(fund_consts)/sizeof(double))" depends on the size
declared for "fund_consts"), which seems unlikely - if it's defined
there, why declare it all over again later in the same module?



More information about the Comp.lang.c mailing list