News for hackers. Stuff that matters.
Re:Beej's Guide to C Programming by tialaramex on Sunday February 26, 2023 @09:39PM (#34952302)
For MMIO loads and stores you want intrinsics which do an MMIO load / store, which is exactly what Rust provides. The fact this is an "address" in "memory" couldn't matter less, it's not really memory, that's just for the convenience of the CPU so that we don't need two extra instructions (and I believe ironically on some embedded CPUs we do have special instructions and we do need to use them for IO to get the desired behaviour, so Rust ends up making that case easier...)

What C does here instead is a type system hack named "volatile" types. Let's label the type so that we know it's not really memory, but then we'll allow all the same operations as for regular types even though that doesn't make much sense. Ideally programmers avoid using any of the resulting nonsense operations, in practice they mostly seem to just hope it magically works, after all the C looks like it should work...

There are no comments on this comment yet.