On 21/09/2011 16:57, Paulo J. Matos wrote:
On 21/09/11 15:21, David Brown wrote:
And since this
situation would not occur in real code (at least, not code that is
expected to do something useful other than test the compiler's code
generation), there is no harm in making sub-optimal object code.
Actually the reason why I noticed this is because one of our engineers
told that GCC stopped generating instructions for certain operations
when he moved from GCC45 to GCC46. This code is real code.
Cheers,
If you really have a "static const" object which you need to read as
"volatile" for some reason, then I would seriously consider changing the
code. With "static const" you are telling the compiler it knows
everything about the use of that object, and its value will never change
- with "volatile" you are telling it that it's value might change behind
the scenes. Obviously you've only posted a code snippet and not your
full code, but that sounds self-contradictory to me. Somewhere along
the line you are lying to the compiler - that's never a good idea when
you want correct and optimal code.
David