Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!lll-lcc!ames!ucbcad!ucbvax!sdcsvax!sdchem!tps
From: tps@sdchem.UUCP (Tom Stockfisch)
Newsgroups: comp.lang.c
Subject: Re: A Deficiency of the C Preprocessor - (nf)
Message-ID: <603@sdchema.sdchem.UUCP>
Date: Wed, 24-Dec-86 13:01:55 EST
Article-I.D.: sdchema.603
Posted: Wed Dec 24 13:01:55 1986
Date-Received: Wed, 24-Dec-86 21:08:59 EST
References: <1259@kontron.UUCP> <6700001@iaoobelix.UUCP>
Sender: news@sdchem.UUCP
Reply-To: tps@sdchemf.UUCP (Tom Stockfisch)
Organization: UC San Diego
Lines: 30

In article <6700001@iaoobelix.UUCP> woerz@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@sdcsvax.UCSD