Optimizing out unreferenced variables

Chris Lewis clewis at ferret.ocunix.on.ca
Tue May 7 23:53:45 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 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've not tried this myself, but I would presume that if the compiler
is ANSI compliant, you can probably declare such variables "volatile"
and the compiler will not optimize them out.  Volatile does work in
similar situations with the RS/6000 compiler.
-- 
Chris Lewis, Phone: (613) 832-0541, Domain: clewis at ferret.ocunix.on.ca
UUCP: ...!cunews!latour!ecicrl!clewis; Ferret Mailing List:
ferret-request at eci386; Psroff (not Adobe Transcript) enquiries:
psroff-request at eci386 or Canada 416-832-0541.  Psroff 3.0 in c.s.u soon!



More information about the Comp.unix.programmer mailing list