Re: [coldfire-gnu-discuss] The option -fkeep-static-consts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldfire-gnu-discuss] The option -fkeep-static-consts



DMS Tech, John wrote:
> I am using the G++ 4.1-32 version. I have some static constants in my
> code and whenever I use a optimization option (-O1, ..) these static
> constants disappear from my compiled output file.

The compiler is behaving as expected:

`-fkeep-static-consts'
     Emit variables declared `static const' when optimization isn't
     turned on, even if the variables aren't referenced.

When optimization is on, the compiler always removes unreferenced static
constants.  Older versions of the compiler may not have been smart
enough to do so.

The option is actually intended to be used in the negative:

  m68k-elf-gcc -g -fno-keep-static-consts a.c

compiles a.c without optimization, but throws away unreferenced static
constants.  Without the option, they would be kept.

To keep the static ocnstants at all optimization levels, use the "used'
attribute:

  static const int i __attribute__((used)) = 7;

-- 
Mark Mitchell
CodeSourcery
mark@xxxxxxxxxxxxxxxx
(650) 331-3385 x713