lvalues -> incomplete types

  • Thread starter Mantorok Redgormor
  • Start date
M

Mantorok Redgormor

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?
 
P

pete

Mantorok said:
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?

An lvalue isn't how you use an expression.
An lvalue is a kind of expression.

x = y; /* Two lvalues */
 
J

Jeremy Yallop

pete said:
An lvalue isn't how you use an expression.
An lvalue is a kind of expression.

x = y; /* Two lvalues */

Which expressions have incomplete type (other than void) and don't
violate a constraint?

Jeremy.
 
P

pete

Jeremy said:
Which expressions have incomplete type (other than void) and don't
violate a constraint?

/* BEGIN new.c */

#include <stdio.h>

extern int array[];

int main(void)
{
int x;

x = array[5000];
return 0;
}

/* END new.c */
 
J

Joe Wright

pete said:
An lvalue isn't how you use an expression.
An lvalue is a kind of expression.

x = y; /* Two lvalues */
No. Only x might be an lvalue. y is an rvalue.
 
J

Jack Klein

No. Only x might be an lvalue. y is an rvalue.

Assuming y is the name of an object of a type that is assignment
convertible to the type of x, rather than a macro or enumerated
constant, than y in this expression is most certainly an lvalue.

The assignment statement performs "lvalue to value" conversion,
by accessing the value of the object. The result of this conversion
is a pure value, and no longer an lvalue, but that does not mean that
y itself is not an lvalue.

Note also that this used to be called "lvalue to rvalue" conversion,
but the term "rvalue" is no longer used in the current C standard
except for a footnote that this formerly used term has been replaced
by the phrase "value of an expression".

Here's the actual quote from 6.3.2.1 Lvalues, arrays, and function
designators, paragraph 2, of the current C standard:

"Except when it is the operand of the sizeof operator, the unary &
operator, the ++ operator, the -- operator, or the left operand of the
.. operator or an assignment operator, an lvalue that does not have
array type is converted to the value stored in the designated
object (and is no longer an lvalue). If the lvalue has qualified type,
the value has the unqualified version of the type of the lvalue;
otherwise, the value has the type of the lvalue. If the lvalue has an
incomplete type and does not have array type, the behavior is
undefined."
 
J

Joe Wright

Jack said:
Assuming y is the name of an object of a type that is assignment
convertible to the type of x, rather than a macro or enumerated
constant, than y in this expression is most certainly an lvalue.

The assignment statement performs "lvalue to value" conversion,
by accessing the value of the object. The result of this conversion
is a pure value, and no longer an lvalue, but that does not mean that
y itself is not an lvalue.

Note also that this used to be called "lvalue to rvalue" conversion,
but the term "rvalue" is no longer used in the current C standard
except for a footnote that this formerly used term has been replaced
by the phrase "value of an expression".

Here's the actual quote from 6.3.2.1 Lvalues, arrays, and function
designators, paragraph 2, of the current C standard:

"Except when it is the operand of the sizeof operator, the unary &
operator, the ++ operator, the -- operator, or the left operand of the
. operator or an assignment operator, an lvalue that does not have
array type is converted to the value stored in the designated
object (and is no longer an lvalue). If the lvalue has qualified type,
the value has the unqualified version of the type of the lvalue;
otherwise, the value has the type of the lvalue. If the lvalue has an
incomplete type and does not have array type, the behavior is
undefined."
Ok Jack, thanks. Aren't standards wonderful? In the old days, "An object
is a manipulatable region of storage; an lvalue is an expression
referring to an object." Short and sweet. Thanks again.
 
P

pete

Joe said:
Ok Jack, thanks. Aren't standards wonderful?
In the old days, "An object
is a manipulatable region of storage; an lvalue is an expression
referring to an object." Short and sweet.

A dereferenced pointer to object type, is also an lvalue.
That's the kind of lvalue, which gives undefined behavior,
if it doesn't refer to an object when evaluated.
But, they've kept the word "dereferenced" out of the standard, so far.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top