LWN.net Logo

ACCESS_ONCE()

ACCESS_ONCE()

Posted Aug 13, 2012 9:56 UTC (Mon) by dgm (subscriber, #49227)
In reply to: ACCESS_ONCE() by daglwn
Parent article: ACCESS_ONCE()

> How can the compiler possibly know what you meant when you wrote something outside the language spec?

The code we are arguing about, the one with ACCESS_ONCE(), is NOT outside the spec in any way, is it?


(Log in to post comments)

ACCESS_ONCE()

Posted Aug 13, 2012 12:11 UTC (Mon) by nye (guest, #51576) [Link]

>> How can the compiler possibly know what you meant when you wrote something outside the language spec?

> The code we are arguing about, the one with ACCESS_ONCE(), is NOT outside the spec in any way, is it?

No it isn't. The point is that, absent the ACCESS_ONCE() macro, the assumption that the compiler shouldn't pull that access out of the loop is what's outside the language spec, because the spec says it can safely do so.

ACCESS_ONCE()

Posted Aug 17, 2012 10:57 UTC (Fri) by dgm (subscriber, #49227) [Link]

> the spec says it can safely do so.

But does the spec say it _has_ to do so? Does it more good or harm?

Not everything that is allowed is good. For example, the compiler is (in theory) allowed to do anything it wants when presented with code that raises undefined behavior. Anything. "rm -rf /" for instance would be 100% correct. Are GCC developers planing this "feature" for gcc 4.8? Of course not, that would be stupid when you could be playing nethack instead...

ACCESS_ONCE()

Posted Aug 13, 2012 16:35 UTC (Mon) by daglwn (subscriber, #65432) [Link]

Yes, it is. It uses typeof().

But ignoring that, nye has the more useful response. :)

ACCESS_ONCE()

Posted Aug 17, 2012 10:37 UTC (Fri) by dgm (subscriber, #49227) [Link]

typeof() is clearly something acceptable in gcc's C dialect. Or have they removed their own extension without the word noticing?

ACCESS_ONCE()

Posted Aug 20, 2012 10:07 UTC (Mon) by etienne (subscriber, #25256) [Link]

The thing is, can the type returned by typeof() be modified by adding the "volatile" keyword, how much can it be modified (how to remove volatility, possible to change the sign-ness by adding signed/unsigned)...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds