Optimizing out unreferenced variables

Rob Marchand rob at array.UUCP
Thu May 9 01:19:32 AEST 1991


In article <608 at elroy> davidk at dsinet (David Karr) writes:
|I have been hearing about a tendency for certain Unix optimizing C compilers
|to deal harshly with static variables declared in C modules that are not
|referenced in that module.  In other words, it will delete those variables
|from the object file.  A controversial example would be variables declared
|in each module to hold RCS or SCCS information.  Often these variables will
|be declared as static, and only used by certain utilities to parse out the
|version numbers from an executable binary.

	I have seen this as well.

|I was told that the C compiler on AIX has this particular "affliction".  Is
|this a general feature of optimizing C compilers, and will more compilers
|be adding this "feature" as time goes on, or is the AIX compiler a fluke?  I
|heard a mention that the HP 700 compiler would be doing this in the future.

	I believe that an older version of the VMS C compiler would 
	optimize out static variables that were not used.  The case with RCS
	that you mention is in fact the way I found this out.  I don't
	know about newer versions of the compiler...
	More an inconvenience than anything, but in some cases it is
	sure handy to be able to identify the contents of the binary
	with certainty.   I guess the question is whether you also patch
	the RCS $id$ string when you do binary patches to the file :-)
	Kidding!  Just kidding!

	Cheers!
	Rob Marchand
-- 
Rob Marchand                   UUCP  : uunet!attcan!lsuc!array!rob
Array Systems Computing        ARPA  : rob%array.UUCP at uunet.UU.NET
401 Magnetic Drive, Unit 24    Phone : +1(416)736-0900   Fax: (416)736-4715
Downsview, Ont CANADA M3J 3H9  Telex : 063666 (CNCP EOS TOR) .TO 21:ARY001



More information about the Comp.unix.programmer mailing list