473,809 Members | 2,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lvalues and Rvalues

i was reading soemthing about Lvalues Rvalues and modifiable
Lvalues....
i am confused now...
like for eg
int *y , x ;
y = &x ;
in the second is x a lvalue or rvalue
any pointers on some good reading on lvalues and rvalues on the web ??
thanks in advance
Kind Regard
rahul

Oct 14 '06 #1
3 2728
ra************* ******@gmail.co m wrote:
i was reading soemthing about Lvalues Rvalues and modifiable
Lvalues....
i am confused now...
like for eg
int *y , x ;
y = &x ;
in the second is x a lvalue or rvalue
any pointers on some good reading on lvalues and rvalues on the web ??
thanks in advance
Kind Regard
rahul
Well, there really isn't much to it, if I get where you're going. You
might want to read up on http://c-faq.com/ .... this is a general C-FAQ,
but you kind of asked a general question, so...
Oct 14 '06 #2
"ra************ *******@gmail.c om" <ra************ *******@gmail.c omwrites:
i was reading soemthing about Lvalues Rvalues and modifiable
Lvalues....
i am confused now...
like for eg
int *y , x ;
y = &x ;
in the second is x a lvalue or rvalue
any pointers on some good reading on lvalues and rvalues on the web ??
An "lvalue" is an expression that (potentially) designates an object.
The origin of the term is "left value", i.e., something that can
appear on the left side of an assignment statement (though not all
lvalues can actually appear on the left side of an assignment
statement).

In your example above:
y = &x;
both y and x are lvalues; the operand of a unary "&" must be an
lvalue, since "&" takes the address of an object. (It's not *quite*
that simple, but don't worry about it.)

A "modifiable lvalue" is an lvalue that refers to an object that can
be modified (for example, one that isn't declared as const).

The C standard doesn't actually use the term "rvalue". You can think
of an rvalue as any expression that isn't used as an lvalue, or
(loosely) as an expression that can appear on the right side of an
assignment.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 14 '06 #3
"ra************ *******@gmail.c om" <ra************ *******@gmail.c omwrote:
# i was reading soemthing about Lvalues Rvalues and modifiable
# Lvalues....
# i am confused now...
# like for eg
# int *y , x ;
# y = &x ;
# in the second is x a lvalue or rvalue
# any pointers on some good reading on lvalues and rvalues on the web ??
# thanks in advance

Unfortunately except for Algol 68 and assmebly language,
variableness is left out of type systems, requiring instead
much verbal handwaving that could be more precise.

Borrowing & from C++ with restriction that a reference type
cannot be inside any other type, then when you declare a
scalar and array,
T v,w[n],*x;
v has type (&T), w has type (*T), and x has type (&*T).

Then the pointer/variable operator types are
v = e
v is coerceable to type &T
and e is coerceable to type T
and (v=e) is type T
*x
x is coercecable to *T
and *x is type &T
&v
v is coercecable to &T
and &v is type *T
s.f
If s is coercable to &T and f has nonreference type S,
(s.f) has type &S [endowed with subnames in Algol 68].
If s is not coercable to T and f has nonreference type S,
(s.f) has type S.
LOAD(v) is an implicit operator
v is coerceable to &T
and LOAD(v) is type T

Expressions q in the language is then applied to one of two implicit
functions LVALUE(q) or RVALUE(q)
LVALUE(q) = q and q must have type &T
RVALUE(q) = LOAD(q) if q has type &T
RVALUE(q) = q if q has type T which is not a reference type

The pointer/variable operator implicits are
LVALUE(v) = RVALUE(e)
* RVALUE(x)
& LVALUE(x)
s . f - There is no implicit on s.
A variable by itself has its declared type, T or &T.
All other expressions are
prefixop RVALUE(operand)
RVALUE(leftoper and) infixop RVALUE(rightope rand)
RVALUE(predicat e) ? RVALUE(truebran ch) : RVALUE(falsebra nch)

GCC has an alternate rule for ?: - there is no implicit RVALUE or
LVALUE on the branches except they must be coerceable to a balanced
type T, T may be a reference type.
(p?v:*x) = e
LVALUE((RVALUE( p) ? v : *RVALUE(x))) = RVALUE(e)
with the types LVALUE(RVALUE(i nt) ? &T : *RVALUE(&*T)) = RVALUE(S)
LVALUE(RVALUE(i nt) ? &T : *(LOAD(&*T))) = S
LVALUE(RVALUE(i nt) ? &T : *(*T)) = S
LVALUE(RVALUE(i nt) ? &T : &T) = S
LVALUE(&T) = S
&T = S
and if S is coerceable to T, the assignment is valid in GCC,
but in ANSI C, the types are T=S which is invalid.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
Oct 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
404
by: Steven T. Hatton | last post by:
This is from the draft of the previous version of the Standard: http://www.kuzbass.ru:8086/docs/isocpp/expr.html 2- A literal is a primary expression. Its type depends on its form (lex.literal). A string literal is an *lvalue*; all other literals are *rvalues*. -4- The operator :: followed by an identifier, a qualified-id, or an operator-function-id is a primary-expression. Its type is specified by the
6
1847
by: amparikh | last post by:
I know this is something fundamental and I ought to have known it, but somehow this seems to be confusing me a lot. Fundamentally, rvalues and/or temporaries can be bound only to constant references going by the const guidelines. Taking that into consideration, how does one get a constant reference to a pointer. class A
7
1751
by: Mantorok Redgormor | last post by:
An lvalue is an expression with an object type or an incomplete type other than void;53) if an lvalue does not designate an object when it is evaluated, the behavior is undefined. When would one ever use an incomplete type as an lvalue?
23
3974
by: steve.j.donovan | last post by:
Hi guys, We have the following macro: #define NEXT(type,p) (*((type*)(p))++) It provides a way to poke variable sized data into an array of pcode for a simple VM. e.g,
232
13385
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
61
2828
by: jacob navia | last post by:
Continuing the discussion about casts, I would like to know your opinions about the hairy subject of casts as lvalues, i.e. This will fail under lcc-win32, but MSVC and gcc will accept it. I know that the standard prescribes the behavior that lcc-win32 uses, but I left that behavior after a big discussion about this several years ago. I had modified it, and some people raised hell.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.