2 ms·
volatile 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 vo
by Sir_Cmpwn 11y ago
volatile 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.