by AnimalMuppet · 11y ago · 0 comments
But you still can write stuff that looks just like C, that a C compiler will accept, and that lets you take advantage of your system architecture. You just need to understand that a new version of your compiler can break all of your nifty tricks.
1. Those that communicate with the outside world exclusively via library calls to an operating system.
2. Those that do not.
People that live in world #1, usually don't get people living in world #2. Example.
// wait for write ready
while((spi.S & SPI_S_SPTEF_MASK) == 0)
;
spi.D;
spi.D = data;
Guess what,No spi.D; is actually important. No just because the program never writes to spi.S does not mean you can delete the while loop. No you cannot reorder any of this and have it work.
Based on your comment it seems clear that you understand that... but given that you understand that I don't get the point you're trying to make (except perhaps that writing low-level hardware code in C often means actively stopping the compiler from screwing you over).
(for non-C programmers: "volatile" can be approximated by "hey compiler, this variable can change unexpectedly even if you didn't do anything to change it, so don't use any optimizations that assume you're the only one changing it).
Disclaimer: I have no C experience.