1 Nov 2006 11:19
whether the placement of "volatile" makes a difference
Robert P. J. Day <rpjday <at> mindspring.com>
2006-11-01 10:19:28 GMT
2006-11-01 10:19:28 GMT
from the definition of an "atomic" variable in the linux kernel,
there are numerous arch-specific header files that define an atomic
variable in one of two ways:
1) typedef struct { int counter; } atomic_t;
2) typedef struct { volatile int counter; } atomic_t;
the purported need for the "volatile" type qualifier is to guarantee
that the (gcc) compiler doesn't try to do anything clever with code
generation, of course, which makes sense.
the problem is that some architectures add the "volatile" qualifier,
while others don't. but whether it's necessary isn't just related to
the architecture, is it? wouldn't it be related to just the
properties of the compiler itself?
second, even if an architecture didn't strictly *need* that
qualifier, would it hurt to have it there? surely having an
unnecessary "volatile" qualifier couldn't break code that would
otherwise work, could it? it would only prevent some possible
optimization, no?
and, finally, in some of those header files, even if the typedef
doesn't use "volatile", some of the function definitions do:
static inline int atomic_add_return (int i, volatile atomic_t *v) {
^^^^^^^^
i find this curious. in this particular header file, while the
(Continue reading)
RSS Feed