3 ms·
> this approach is very common in Unix world, with memory-mapped HW registers represented by C structs and so on The "correct" way to do this is to write the b
by saagarjha 8y ago
> this approach is very common in Unix world, with memory-mapped HW registers represented by C structs and so on
The "correct" way to do this is to write the bare minimum assembly needed to present this view to a programmer in C (so there's no need to worry about undefined behavior), then write standards compliant code from there. Writing all this code in C is just papering over the fact that what you're doing is architecture-specific and should be treated as such.
- dfox 8y agoThat is exactly my approach to this issue (and at least gcc seems to be clever enough to mostly optimize the abstraction layer away). On the other hand you will see the direct approach with structs directly mapping to hardware, questionable uses of volatile to make the thing actually work and so on very often in various production code.