Are arrays guaranteed to be affected by a "memory" clobber?

Andrew Haley aph@redhat.com
Thu Jun 11 11:23:00 GMT 2015


On 06/11/2015 12:21 PM, Andrew Haley wrote:
> On 06/10/2015 09:46 PM, Sebastian wrote:
>> The reason why I would like to avoid the volatile qualifier:
> 
>> As soon as I use it once, I must use it in all functions which get a
>> pointer to the buffer. So I can't reuse these functions for other
>> arrays.
> 
>> With other variables, this is not so serious - you can assign the
>> value of a volatile variable to a temporary variable, or to a
>> parameter, without trouble. Only with pointers/arrays, this becomes
>> a problem.
> 
> I'd use a full memory barrier.  __sync_synchronize() or one of the
> __atomic fences.  Even if your processor does not use a relaxed
> memory model, this guarantees that no memory operations will not
> be moved  across the barrier.

erm, assuming that your target does not emit calls to nonexistent
routines when you do this.  It'd be a bug, but I'm not sure if some
targes still do.

Andrew.




More information about the Gcc-help mailing list