From: Grant Edwards <grant.b.edwards@gmail.com>
To: gdb@sources.redhat.com
Subject: Re: printing static const variables
Date: Thu, 16 Jul 2009 17:28:00 -0000 [thread overview]
Message-ID: <h3nnup$aq0$1@ger.gmane.org> (raw)
In-Reply-To: <97A121F2-C4CB-4244-9F71-1D0B9BA60638@ericgorr.net>
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
prev parent reply other threads:[~2009-07-16 17:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-16 16:16 Eric Gorr
2009-07-16 16:21 ` Tom Tromey
2009-07-16 16:35 ` Eric Gorr
2009-07-16 16:56 ` Tom Tromey
2009-07-16 17:28 ` Grant Edwards [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='h3nnup$aq0$1@ger.gmane.org' \
--to=grant.b.edwards@gmail.com \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox