As a low-level programmer I am looking for particular features in a language and I haven’t found them in Zig yet. Please help me on these:
Volatile Variables — Zig seems to offer volatile pointers, but not volatile variables. Is it a part of the “friction” in language design? Is the following an intended construct? (extracted from [link])
var tick_counter: u32 = 0; // updated in an IRQ
pub fn getTicks() u32 {
return @as(*volatile u32, @ptrCast(&tick_counter)).*;
}
I would argue that volatile should be reserved only for MMIO as they are the natural way to communicate from an IRQ to the application in the absence of an OS
Compiler barriers — in Zig I haven’t found any way to tell the compiler to ensure that all assignment statements up to a certain point in the code are executed before I can proceed with a DMA transaction or perform any other operation which requires all data in memory. Making everything volatile will not help in such case as they generate overhead with each access.
Guaranteed structure layout in memory — I haven’t found any information that it is possible in Zig to create structures with predictable layout, so they would map peripheral registers. What is the intended way to deal with peripherals with registers?