Re: C++ standards question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Feb 3, 2013 at 3:24 PM, John Fine <johnsfine@xxxxxxxxxxx> wrote:
> I have a construct that the optimizer in VS2010 64-bit changes to something
> that doesn't work.
>
> I want to know whether this is a bug in the compiler or in the code being
> compiled.
>
> I would have no idea where to look in the standards document for this
> answer.  I know it is off-topic (a C++ not gcc question) but this is where
> the experts are.
>
> My function takes a parameter char* p
> One of the things the function does is test and conditionally modifies a
> char pointed to through P.  Something like:
>
> if ( expression of *p ) *p = '-';
>
> The optimizer changes that to the equivalent of
>
> *p = (expression of *p ) ? '-' : *p;
>
> Is that a valid optimization?

Not these days, and current GCC should not do it.

This is called a speculative store.

Oh, wait, you were asking about Visual Studio (at least, I am guessing
that that is what you mean by VS2010).  Speculative stores are
disallowed by the C++11 memory model.  So when VS2010 supports C++11,
it will no longer perform this optimization.  That said, I am told
that Visual Studio still does not support C99 more than ten years
later, so who knows if it will ever support C++11.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux