Warning: volatile does NOT do what you think it does. WRT. DS or similar development.

Sean Kelly sean at invisibleduck.org
Mon Jan 12 14:33:20 PST 2009


downs wrote:
> Yesterday, I tried porting parts of libnds (the open-source utility library for the Nintendo DS) to D.
> 
> Worked relatively fine too, templates work, structs work, volatile DOESN'T WORK.
> 
> Let me repeat that. Volatile Doesn't Work.
> 
> This was my code:
> 
>> struct VolatilePointerProxy(T) {
>>   T* ptr;
>>   T access(T i) { volatile (*ptr) = i; return i; }
>>   T access() { T res; volatile res = *ptr; return res; }
>>   mixin(PropertyForward!("access"));
>> }
> 
> This prevents the compiler from optimizing memory accesses past access().
> 
> It does *NOT* prevent the compiler from removing "redundant" calls to access.

That's not a legal optimization of 'volatile'.  I'd file a bug report.


Sean



More information about the Digitalmars-d mailing list