A Deficiency of the C Preprocessor - (nf)

Tom Stockfisch tps at sdchem.UUCP
Thu Dec 25 04:01:55 AEST 1986


In article <6700001 at iaoobelix.UUCP> woerz at iaoobelix.UUCP writes:
>> We are developing programs where an array of structures exists.
>>
>>         #define BRKPTCOUNT      5
>>         struct .... FooBar[BRKPTCOUNT] = {....};
>>
>> Everytime we change BRKPTCOUNT, we have to change the initialization data
>> for FooBar...

>Why don't you write your structures and defines like this:
>
>    #define BRKPTCOUNT  (sizeof (FooBar)/sizeof (FooBar[0]))
>    struct ... FooBar [] = { ... } ;

I think what he wants is to choose
brkptcount and then have that many
(identical?) units put between the {}'s
to initialize FooBar.  Also note that
your solution does not work if
BRKPTCOUNT is to be used in a different
file, since the other file won't be able
to specify the array size in it's decl
of FooBar.  You can change "#define" to
"int", but then you no longer have a
constant.  I think its impossible to
determine the size of an array in a
different module, unless that module
communicates the size explicitly.

|| Tom Stockfisch, UCSD Chemistry	tps%chem at sdcsvax.UCSD



More information about the Comp.lang.c mailing list