C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

volatile vs. assignment

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Balog Pal
Guest





PostPosted: Fri Feb 20, 2004 8:05 pm    Post subject: volatile vs. assignment Reply with quote



on clcm I read a claim that conforming to the standard having a volatile
object, assignment to it will have a lvalue->rvalue conversion at the end
that shall not be discarded. Thus

extern volatile int v;

v=1;

will emit code with a write to the location, *and then a read access* to
that same location. What may lead to unexpected events if v is some memory
mapped i/o register.

A recent post counters it:
- ---------
"Ben Hutchings" <do-not-spam-benh (AT) bwsint (DOT) com> wrote

(on clc++m)
Quote:
Jack Klein wrote:
snip
Note that under the current C++ standard, assigning to a volatile
object yields an lvalue result. An lvalue in an expression calls for
an lvalue-to-rvalue conversion in the abstract machine, and can
normally be optimized away if the rvalue is not used.
snip

The lvalue-to-rvalue conversion is done in "a context where an rvalue
is expected" (3.10/7), e.g. where the lvalue appears as a sub-
expression, initialiser or return statement which requires an rvalue.
An expression statement is not such a context (6.2/1), so

b = a;

requires lvalue-to-rvalue conversion on a but not on b. However,

c = b = a;

requires lvalue-to-rvalue conversion on both a and b but not c.
- -------------------


What is the truth in this question -- is that read mandatory, optional or
forbidden?

Paul


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.