On Mon, Nov 24, 2014 at 5:30 AM, David Howells <dhowells@xxxxxxxxxx> wrote: > Christian Borntraeger <borntraeger@xxxxxxxxxx> wrote: > >> +#define get_scalar_volatile_pointer(x) ({ \ >> + typeof(x) *__p = &(x); \ >> + volatile typeof(x) *__vp = __p; \ >> + (void)(long)*__p; __vp; }) >> +#define ACCESS_ONCE(x) (*get_scalar_volatile_pointer(x)) > > Might this cause two loads from memory under some conditions? Once for the > fourth line and once for the fifth? Hmm. Since the fourth line isn't volatile, I'd expect gcc to optimize it away. But you're right, it might be safer to make sure the "test type" part is something like (void)sizeof((long)*__p) instead - the "sizeof()" means that it will never actually get evaluated, but the type-checking of casting *__p to (long) will still catch the case of *__p being some non-scalar type that cannot be cast. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-x86_64" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html