Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!unido!iaoobelix!woerz From: woerz@iaoobelix.UUCP Newsgroups: comp.lang.c Subject: Re: A Deficiency of the C Preprocessor - (nf) Message-ID: <6700001@iaoobelix.UUCP> Date: Sun, 21-Dec-86 22:36:00 EST Article-I.D.: iaoobeli.6700001 Posted: Sun Dec 21 22:36:00 1986 Date-Received: Tue, 23-Dec-86 23:39:45 EST References: <1259@kontron.UUCP> Lines: 34 Nf-ID: #R:kontron:-125900:iaoobelix:6700001:000:1201 Nf-From: iaoobelix!woerz Dec 22 04:36:00 1986 > I've got a complaint about the C preprocessor -- I doesn't support a > repetition for initializing data structures. > > 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; if we give extra initialization data, we get complaints from the > compiler; if we don't give enough data, the rest of the structure isn't > initialized. Why don't you write your structures and defines like this: #define BRKPTCOUNT (sizeof (FooBar)/sizeof (FooBar[0])) struct ... FooBar [] = { ... } ; Then your array will be maid as large as needed to fit your data. The size of the array (defined by BRKPTCOUNT) will be computed during compile time, since sizeof is a compile time function and the whole expression is constant. > ... ------------------------------------------------------------------------------ Dieter Woerz Fraunhofer Institut fuer Arbeitswirtschaft und Organisation Holzgartenstrasse 17 D-7000 Stuttgart 1 W-Germany BITNET: ...unido.bitnet!iaoobel.uucp!woerz UUCP: ...seismo!unido!iaoobel!woerz