This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: printing static const variables
On 2009-07-16, Eric Gorr <mailist@ericgorr.net> wrote:
> I still see the same problem if change the test function to:
>
> Boolean TestFunction( int val )
> {
> static const int doubleByteDegreeMark = 42;
> static int anotherVar = 12;
>
> return ( val == doubleByteDegreeMark || val == anotherVar );
> }
>
> Now, I suppose it is still possible that the compiler will have simply
> optimized this to:
>
> Boolean TestFunction( int val )
> {
> static int anotherVar = 12;
>
> return ( val == 42 || val == anotherVar );
> }
>
> or something.
More likely it'll be optimized to
Boolean TestFunction( int val )
{
return ( val == 42 || val == 12 );
}
There's no requirement that the compiler have a setting that
doesn't optimize your function to that shown above.
Since anotherVar isn't visible outside TestFunction, and isn't
assigned to inside TestFunction, the compiler is free to treat
it as a constant.
--
Grant Edwards grante Yow! You were s'posed
at to laugh!
visi.com