A Deficiency of the C Preprocessor

braner braner at batcomputer.tn.cornell.edu
Sat Dec 20 05:07:43 AEST 1986


In article <1259 at kontron.UUCP> cramer at kontron.UUCP (Clayton Cramer) writes:
>I've got a complaint about the C preprocessor -- I doesn't support a
>repetition for initializing data structures.
> ...
>We've worked around this annoyance by defining a function that initializes
>the FooBar, but this takes time and code to do at runtime something that
>should be doable at compile time. ...

I would like, if not that, at least an acceptance by the preprocessor
of more parameters than required.  As for compile vs. run time
initialization of arrays:  A compiler I use creates code for all the
initializations in the program, code that runs when you invoke the program
and copies all the initial data from the code to the variable-data areas.
(To sound technical: from the data (or code) segment to the bss segment.)
This means that during the execution of the program, TWICE the memory is
needed to hold the data.  This is necessary in environments where code
is not to be modified (e.g. ROM), but in other environments is wasteful.

Even worse, when an array is initialized, this compiler generates a line
of code to initialize each entry, rather than an image of the array and
looping code. This approximately DOUBLES the length of the initialization
section of the code (and the total memory use is now TRIPLE what it could
be...).  Is this typical for C compilers?  Could you compiler-writers
avoid this in the future, please?

- Moshe Braner



More information about the Comp.lang.c mailing list