4 ms·
"A New C Compiler" by Ken Thompson
- spitfire 17y agoI notice whenever an interesting topic gets posted on HN, the authors/websites other work invariably starts to get posted a few hours later. (This is related to the recent systems research is dead posts) Why is that? Why the need when the links are already there for people who are interested?
- beza1e1 17y agoIt probably is the researching/browsing king of people. Sometimes when i find a good article via HN and i go exploring for more good stuff from the same author/website. This leads to more interesting things, which i could submit to HN.
- 10ren 17y agoPosting a link enables a discussion specific to that link. Note: they're upvoted, not just posted.
- uriel 17y agoKen also wrote another paper describing the same compiler suite which is a bit more uptodate: http://doc.cat-v.org/plan_9/4th_edition/papers/compiler http://doc.cat-v.org/plan_9/4th_edition/papers/compiler
- miracle 17y ago"Volatile seems to have no meaning, so it is hard to tell if ignoring it is a departure from the standard." Try writing a program reading from a memory mapped hardware device. This won't work without volatile.
- uriel 17y agoVolatile doesn't do what you think it does. And I would add that the Plan 9 kernel and all its drivers do just fine without it.
- alain94040 17y agoFor devices with read side-effects, how do you tell the compiler to forgo all optimizations, reordering, etc.? To me, volatile means that if I read a pointer twice, the compiler has to make accesses both times to the memory. It can't assume that since no other function was called in between, it can safely ignore the second read and use the previous value. On ther other hand, you want your compiler to perform such optimizations 99% of the time. So just saying that Plan 9 accesses are all treated as if they were volatile (I googled quickly the topic) doesn't make sense to me. But I confess some ignorance :-)
- phugoid 17y agoThe pointer optimization you're talking about is possible in C, because of potential pointer aliasing. Say you have the following sequence: val = [asterix]p1 [asterix]p2 = 1 val = [asterix]p1 p2 might actually point to the same location as p1, so you can't avoid fetching from memory the second time. IIRC volatile means that a variable cannot be optimized away completely, or moved to a register. This is necessary for memory-mapped architectures when you must access memory to communicate with the hardware (as opposed to storing values). EDIT: trying to get the asterisks to work in this post...
- neilc 17y agop2 might actually point to the same location as p1, so you can't avoid fetching from memory the second time. Not necessarily: if p1 and p2 are of different types (and neither is char * or void *), then the compiler is free to assume that they don't point to the same location. This is called "strict aliasing" per the C99 spec; it breaks a lot of old C code. http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html http://www.cellperformance.com/mike_acton/2006/06/understand... But in any case, this isn't related to "volatile" as such.
- phugoid 17y agoThanks for the correction.