jeff@dad.UUCP (Jeff Loucks) (04/28/88)
In article <20224@think.UUCP> barmar@think.COM (Barry Margolin) writes: >In article <174@obie.UUCP> wes@obie.UUCP (Barnacle Wes) writes: >>In article <20065@think.UUCP>, barmar@think.COM (Barry Margolin) writes: >>> a = b; >>> a = b; >>> It doesn't take much of a flow analysis to determine that the second >>> statement is redundant. Most peephole optimizers will hack this. >>Aha! But this code is not always redundant! > >I know, but it usually is. And that's the whole point of "volatile": >it tells the compiler not to assume that such code is redundant, among >other things. You certainly wouldn't want a compiler to generate >double accesses for all such cases, just the ones where a or b is >volatile. Finally, somebody gets back near the point: C is a wonderful tool for programming computers, from kernal to applications, so we use it. We often write code that will NEVER move to another machine for whatever reason, so portability is not necessarily the issue. What IS the issue? We want our programming tool to be effective (high level enough to save us from assembler), efficient (optimizations are greatly appreciated), and as universally understood as possible (somebody's gotta fix the stuff). However, we also (and usually more importantly) must to be able to do our job (you remember having to do a job don't you?). I have written perfectly legitimate C code that does the equivalent of the a=b; a=b; example above, and have meant every word of it. Consider memory mapped devices; if multiple reads/writes of the same constant value from/to the same location is what you asked for, it's precisely what you should get. Consider shared memory; not only multiple processes, but multiple processors speaking to a common location. If I request a read/write now, I want it NOW. Need I continue? The issue has nothing whatsoever to do with portability, hypothetical CPU architectures, registers, or whatever. It is simply: If I don't want the compiler fiddling with something, I want a reasonable way to tell it so. Period. 'Volatile' works great. What's the big deal? -- uw-beaver!tikal!dad!jeff (jeff loucks (206) h851-8908 w581-1322) ------------- YISDERSOMENIMORORSISASISDENDERISORSIS ? --------------