There’s some uncertainty about the meaning of volatile
in Zig when used for anything but MMIO. There was a thread awhile back about volatile in benchmarking which is worth perusing.
You might consider using std.mem.doNotOptimizeAway here, which should have the correct effect. While it’s likely that any idiomatic-to-C use of volatile
in Zig will work right now, @andrewrk has been pretty clear on the sole use case it’s intended to support, which is MMIO, so if the compiler starts breaking code which doesn’t use volatile
specifically to that purpose, we were fairly warned.