I'm (still) trying to put the "missing bits" of atomic methods together into a 
cross-platform/cross-backend module. I've now got to the point that the VCC C 
version compiles and run (I only test with one thread, so idk if it really 
gives the expected atomic behaviour yet). When I try to build and run the VCC 
C++ version, I have an issue with C++ references. It seems "(t: var T)" is 
translated to a pointer in C, and a reference in C++. And this doesn't seem to 
play well with volatiles.

How to I make this work in C++?
    
    
    type
      VolatilePtr*[T] = distinct ptr T
    
    proc toVolatilePtr*[T](t: var T): VolatilePtr[T] =
      cast[VolatilePtr[T]](addr t)
    
    var my_vbyte {.volatile.}: byte = 0'u8
    var my_vbyte_ptr: VolatilePtr[byte] = toVolatilePtr[byte](my_vbyte)
    
    echo(cast[pointer](my_vbyte_ptr) == nil)
    

When trying to use this, I get this kind of error:
    
    
    error C2664: 'NU8 *toVolatilePtr_WWtk4tL3VWMmQk62xcO0Ew(NU8 &)': cannot 
convert argument 1 from 'volatile NU8' to 'NU8 &'
    

Reply via email to