Topic: volatile
Author: restor <akrzemi1@gmail.com>
Date: Mon, 13 Jul 2009 13:44:48 CST Raw View
> Could any one please explain what the volatile/const volatile is ? How
> do programmers use it adequately ?
Hi, I am probably not the right person to answer your question. I
would also want to know even the low level usage. But you might find
the following link of interest:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2016.html
At some point the C++ Standards Committee were considering changing
the semantics of volatile to be that of an atomic variable. The
document lists the known usages of volatile data.
Regards,
&rzej
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "David Sachs" <sachs1926@comcast.net>
Date: Tue, 14 Jul 2009 14:25:46 CST Raw View
"restor" <akrzemi1@gmail.com> wrote in message
news:2af18954-f2c2-418d-b5e9-d08a33376924@n4g2000vba.googlegroups.com...
>> Could any one please explain what the volatile/const volatile is ? How
>> do programmers use it adequately ?
>
> Hi, I am probably not the right person to answer your question. I
> would also want to know even the low level usage. But you might find
> the following link of interest:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2016.html
> At some point the C++ Standards Committee were considering changing
> the semantics of volatile to be that of an atomic variable. The
> document lists the known usages of volatile data.
>
> Regards,
> &rzej
One use of volatile, that was not listed in the paper referred to above is
to prevent register allocation of particular variables.
Some computers, most notably the Intel Pentium series, use higher precision
for floating point numbers in registers than in memory. In some cases, when
EXACT CONSISTENT values are needed, variables for intermediate results can
be declared volatile to deliberately lose the excess precision.
The following function is NOT guaranteed to return true, even if the
arguments and their product have "reasonable" values.
bool test (double a, double b)
{
double c, d;
c = a * b;
d = a * b;
return ( c == d );
}
Making c and d volatile guarantees that they will have the same value, and
will compare equal, assuming that no out of range condition occurs.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: moongeegee <moongeegee@gmail.com>
Date: Thu, 9 Jul 2009 08:59:03 CST Raw View
Could any one please explain what the volatile/const volatile is ? How
do programmers use it adequately ?
Thanks in advance.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Mathias Gaunard <loufoque@gmail.com>
Date: Thu, 9 Jul 2009 12:32:08 CST Raw View
On 9 juil, 16:59, moongeegee <moongee...@gmail.com> wrote:
> Could any one please explain what the volatile/const volatile is ?
In simple terms, a volatile object may be modified anytime without it
being visible to the compiler, so the compiler is not allowed to use
static analysis to replace reading a variable by its deduced value.
In particular, this also means every read must be performed from
memory, since registers may be out of date also.
> How
> do programmers use it adequately ?
They don't, unless they're programming a driver or the like.
Note that volatile is useless in multi-threaded scenarios, unless the
compiler extends the semantics of the keyword, like MSVC does.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]