Array sizes

Jim Vlcek vlcek at mit-caf.MIT.EDU
Sun Feb 19 13:14:33 AEST 1989


In article <807 at atanasoff.cs.iastate.edu> hascall (John Hascall) writes:
  [In a discussion on using empty array declarations]
>   Of course, adding:
>
>     #define N_FCONSTS (sizeof(fund_consts)/sizeof(double)) 
>
>   then you can use stuff like:
>
>     extern fund_consts[N_FCONSTS];
>
>   elsewhere.
>
>John Hascall
>ISU Comp Center

Will this work?  Presumably, both the #define and the extern
declaration will be in a header file (funds.h, let's say).  If we're
compiling usesfunds.c, and we #include "funds.h", how does the
compiler know the sizeof(fund_consts) to calculate the value
N_FCONSTS?  After all, the definition of fund_consts would be in
funds.c, which we are presumably compiling separately -- it may even
be in a library.

I would think that all one can do in this case is #define N_FCONSTS to
be some hard constant, or another expression which reduces to a hard
constant evaluable at compile time in any module including funds.h.
-- 
Jim Vlcek
vlcek at caf.mit.edu
!{harvard,rutgers}!mit-eddie!mit-caf!vlcek



More information about the Comp.lang.c mailing list