Betrayed by a bitfield
Posted Feb 6, 2012 22:22 UTC (Mon) by
giraffedata (subscriber, #1954)
In reply to:
Betrayed by a bitfield by daglwn
Parent article:
Betrayed by a bitfield
That's very interesting, because it seems to say the provision for
"volatile" is so incomplete as to be a pointless language feature.
Not totally true. It's true that volatile doesn't do what most people expect. Basically, volatile says the data can't be cached in a register ...
I was commenting at a higher level. Never mind what the compiler can and can't do. The question is, what programs can you write in C because it has the "volatile" feature that you couldn't otherwise? Relying on nothing but that the compiler implements the C standard.
I've always understood the originally intended answer to be, "you can write a program that uses memory mapped I/O." But comments in this thread say regardless of how one uses the "volatile" keyword in a program, the compiler may always generate code that arbitrarily writes to memory mapped I/O addresses. There's nothing in the standard to stop it. If so, then you not only can't use memory mapped I/O in a C program, you can't even let a C program — any C program — run in an address space that includes memory mapped I/O regions.
Unless all memory-mapped I/O regions ignore writes.
And it's hard to believe that the definers of "volatile" actually had such a useless thing in mind.
(
Log in to post comments)