Does dereferencing a volatile pointer produce a volatile element?

Nicholas Mc Guire der.herr@hofr.at
Mon Feb 15 16:52:00 GMT 2016


On Mon, Feb 15, 2016 at 11:37:13AM -0500, Jeffrey Walton wrote:
> Hi Everyone,
> 
> As an example:
> 
>     int a[10];
>     volatile int* b = a;
> 
>     for(unsigned i=0; i<10; i++)
>         *b++ = 0;
> 
> When the dereference occurs through b, does it produce a volatile element?
>
as far as I understand volatile this is just telling
the compiler that the assignment here can not be reordered
thats it - it does not change the propertieis of a[] in any
way if that is what you means with "produce volatile elements"
with other words if you later use say a[4] = c (with c not
being volatile) then the compiler can again reorder / optimize
out things as seen fit. 

thx!
hofrat 



More information about the Gcc-help mailing list