When should variables within blocks be allocated?

Adrian McCarthy adrian at mti.mti.com
Tue Jan 23 04:43:57 AEST 1990


In article <15699 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer)
writes:

>[compilers are] free to optimize things away.  In
>particular, unused variables need not be allocated.  Such compilers exist.

So the relatively common practice of trying to get an identification string
into the object and executable files by declaring an otherwise unused
character string may be pointless.  For example, many programmers put a line
like:

  static char *RCSid = "$Header$";

into their code.  When they check it out from their configuration management
system (RCS in this example), $Header$ gets expanded to an identification
string.  Later, they expect a strings-type command to spit out the expansion
of the $Header$.  But if RCSid is never used anywhere else in the program,
some compilers might optimize it away.

A better solution would be to provide a switch/option/qualifier to the
program which simply outputs the string.  That would guarrantee RCSid is not
optimized out and it allows folks on systems without a strings-type command
to also get this information.

>Karl W. Z. Heuer (karl at haddock.isc.com or ima!haddock!karl), The Walking Lint

Aid.



More information about the Comp.lang.c mailing list