This will work, today. It might also continue to work.
Just please bear in mind that Zig isn’t C, and isn’t beholden to C’s semantics. If I had to bet on it, I’d say that for what you’re specifically up to here, volatile
will continue to do what you expect. There are some unanswered questions in the thread I linked to, but your application does fall into
If a given load or store should have side effects, such as Memory Mapped Input/Output (MMIO), use
volatile
.
As the documentation puts it, so it should be fine. Just be aware that it’s an under-specified corner of the language.
I asked some very specific questions about exactly that, which went unanswered. I think you have a correct explanation of volatile
’s current behavior, and a reasonable guess as to its intended future behavior. It would be nice to get some ‘further clarification on volatile’, though.