5 ms·
How to Use the Plan 9 C Compiler [pdf]
- swolchok 11y ago> For different reasons, volatile and const are also ignored. Yikes.
- andrewchambers 11y agoI guess the designers of C realized there are better alternatives when implementing their own compiler.
- fredkbloggs 11y ago> I guess the designers of C realized there are better alternatives when implementing their own compiler. Or maybe they went off the rails and lost their minds, like Bill Shockley.
- mikeash 11y agoConst is mildly useful but doesn't do a whole lot. It's as much of a reminder to the programmer as anything. Volatile's behavior is not really defined by the standard and is rarely useful in any case. I'm pretty sure that you can ignore it and remain a fully compliant C compiler.
- Sir_Cmpwn 11y agovolatile is mostly useful for telling the compiler not to optimize out a variable. For example, if you use memory-mapped I/O, you can mark a pointer to it as volatile to tell the compiler that the hardware will be changing it and it shouldn't make any assumptions about that while optimizing. That's lower level than most people go, though, so I understand that it's not useful for the average C programmer.
- andrewchambers 11y agoWell, they wrote the plan9 kernel using this compiler, it can deal with IO fine.
- plorkyeran 11y agoPlan 9's compiler does not have a very sophisticated optimizer (which is part of why it's so fast), so I suspect that they simply didn't implement anything which would have made volatile necessary.
- mikeash 11y agoRight, if every assignment writes to memory and every expression reads from memory then you've effectively made every variable volatile (according to how compilers typically interpret volatile), so ignoring the qualifier wouldn't hurt anything.
- saysjonathan 11y agoHTML version: http://doc.cat-v.org/plan_9/2nd_edition/papers/comp http://doc.cat-v.org/plan_9/2nd_edition/papers/comp
- fredkbloggs 11y agoThis is not a C compiler; the language it accepts bears only a superficial resemblance to any version (formally standardized or not) of C. The subset of C's original authors responsible for this needed to accept that C was both (a) extremely popular and successful and (b) to their way of thinking, inferior to what they would have wished. That's a tough place to be, but denial is worse.
- vezzy-fnord 11y agoWhy did they need to accept any of that? They were doing a clean-room implementation, and mostly ANSI C-compatible with a significantly simplified preprocessor. Theo de Raadt considered using it for OpenBSD at the turn of the 21st century, but backed out over licensing. I have no idea what angle you're getting at here.
- f2f 11y agoback when the plan9 compilers were introduced to the world [0] POSIX 1003 was less than 3 years old. that they didn't change much in their design since is a testament to a) how good they were and 2) how good their authors were. -- 0: ftp://nic.funet.fi/pub/OS/plan9/doc/plan-9-docs/dist.ps.Z
- fredkbloggs 11y agoOr it could be a testament to how little real-world use Plan 9 saw. This is the same reason Latin doesn't change.
- f2f 11y agoyes, that too :)
- stonogo 11y agoIs there a particular reason that "using a subset of ANSI C" is morally worse than "inventing an entirely new language"? I think you're maybe ascribing some kind of ethical purity to ANSI that it doesn't really have, especially given the popularity of GNU extensions et al.
- i4k 11y agoKen Thompson's C Compiler: http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compile...
- kr7 11y agoI have stopped using #ifdef entirely in favor of #if. The problem with #ifdef is it will silently ignore a misspelled argument. If you use #if in conjunction with the -Wundef flag it will catch it. This can be a major security vulnerability if the #define is enabling a security feature but it gets silently disabled because of a misspelling.