Topic: Volatile reading is a side effect?
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Sun, 6 Jun 2010 15:44:13 CST Raw View
Hello all. Am i reading right that this is undefined behavior in C++0x, but
well defined in C++03?
volatile int a = 0;
int b = a + a;
Two side-effects on "a" are unsequenced with respect to each other. But in
C++03, this doesn't seem to yield undefined behavior because the side effect
isn't a change of its stored value.
Or is this undefined in both C++03 and C++0x? I think i have read something
about that the read of a volatile object is considered to change its stored
value implicitly somewhere.
Any help is greatly appreciated!
--
[ 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: ThosRTanner <ttanner2@bloomberg.net>
Date: Mon, 7 Jun 2010 19:07:06 CST Raw View
On Jun 6, 10:44 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> Hello all. Am i reading right that this is undefined behavior in C++0x,
but
> well defined in C++03?
>
> volatile int a = 0;
> int b = a + a;
>
> Two side-effects on "a" are unsequenced with respect to each other. But in
> C++03, this doesn't seem to yield undefined behavior because the side
effect
> isn't a change of its stored value.
>
> Or is this undefined in both C++03 and C++0x? I think i have read
something
> about that the read of a volatile object is considered to change its
stored
> value implicitly somewhere.
>
> Any help is greatly appreciated!
I can't help thinking it should be undefined, because the result of
doing a - a depends on the order in which you read a. At least + is
symmetric.
--
[ 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<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Tue, 8 Jun 2010 13:39:58 CST Raw View
ThosRTanner wrote:
> On Jun 6, 10:44 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
> wrote:
>
>> Hello all. Am i reading right that this is undefined behavior in C++0x,
>>
> but
>
>> well defined in C++03?
>>
>> volatile int a = 0;
>> int b = a + a;
>>
>> Two side-effects on "a" are unsequenced with respect to each other. But in
>> C++03, this doesn't seem to yield undefined behavior because the side
>>
> effect
>
>> isn't a change of its stored value.
>>
>> Or is this undefined in both C++03 and C++0x? I think i have read
>>
> something
>
>> about that the read of a volatile object is considered to change its
>>
> stored
>
>> value implicitly somewhere.
>>
>> Any help is greatly appreciated!
>>
>
> I can't help thinking it should be undefined, because the result of
> doing a - a depends on the order in which you read a. At least + is
> symmetric.
>
The potential for different results does not make it undefined, it makes it
unspecified. Undefined behaviour is where, in theory, any result is possible
including shutdown of the computer.
--
[ 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<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]