6 ms·
Well, one of the interesting takeaways from the article is that C as specified often does not let you take advantage of your system architecture. The specificat
by pcwalton 11y ago
Well, one of the interesting takeaways from the article is that C as specified often does not let you take advantage of your system architecture. The specification has things like GPUs and segmented memory architectures in mind when it forbids you from doing seemingly reasonable things like taking the difference between the addresses of two separately-allocated objects, even though chances are very good what you're trying to do works just fine on all architectures you care about.
- AnimalMuppet 11y agoYes and no. The standard specification defines a C that is very portable. It is quite reasonable that you cannot portably take advantage of your system architecture, which means you cannot do it using C as defined by the standard. 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.
- ydcvjk 11y agoFinally someone that understands.
- Gibbon1 11y agoNot really because there are two kinds of c programer out there. 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.
- spdionis 11y agoWhy? That's the issue that people should solve. Disclaimer: I have no C experience.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- _dps 11y agoAre you saying something other than "you, the programmer, must declare spi to be volatile, or else the compiler might lay a bear trap for you?". 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).
- ydcvjk 11y agoSorry, I have no idea what you are trying to say. Maybe stick to the relevant issue and be less abstract?
- icedchai 11y agoHis example is anything but abstract. Embedded programming is a world unto itself. You sometimes need to read an address before you can write, etc.
- dllthomas 11y agoI think the parent meant "implicit" rather than "abstract". The code is not abstract; but the pragmatic intent of the comment is not made very clear. I believe I follow but I'm not confident enough to risk confusing things by guessing. (I believe I follow the intended conversational import; I certainly follow the code.)
- MichaelCrawford 11y agoIve worked on embedded systems where stuff like that would be a problem, howver I also knew the memory map for my target. I wanted to make some crypto run faster so i used memcpy on a pointer to a function to copy executable code from slow flash to fast ram.