 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
lovecreatesbea...@gmail.c Guest
|
Posted: Sun May 20, 2007 9:11 am Post subject: The result of ++ is not an lvalue? |
|
|
K&R2, both sec A7.3.4 Postfix Incrementation and secA.7.4.1 Prefix
Incrementation Operators say that "The result is not an lvalue". Is
this correct? I don't see an errata on these points. If below the p++
or ++p is not an lvalue, then *p++ or *++p is a syntax error.
When it talks about Unary Operators, why doesn't the secA7.4 collect
both the prefix and postfix incrementation operators together?
int main(void)
{
char a[10] = {0}, *p = a;
/* a[0] = 'a'; a[1] = 'b'; */
/* *p = 'a'; *(p+1) = 'b'; */
/* *p = 'a'; *p++ = 'b'; p--; */
*p = 'a'; *++p = 'b'; p--;
return 0;
} |
|
| Back to top |
|
 |
Martin Ambuhl Guest
|
Posted: Sun May 20, 2007 9:11 am Post subject: Re: The result of ++ is not an lvalue? |
|
|
lovecreatesbea...@gmail.com wrote:
| Quote: | K&R2, both sec A7.3.4 Postfix Incrementation and secA.7.4.1 Prefix
Incrementation Operators say that "The result is not an lvalue". Is
this correct?
|
Yes. The result is a value, and specifies nothing about where it is.
An lvalue must have a location associated with it.
| Quote: | I don't see an errata on these points.
|
Errata are reserved for errors. Why should there be an erratum for
something not in error?
| Quote: | If below the p++
or ++p is not an lvalue, then *p++ or *++p is a syntax error.
|
Really? Why would you claim that?
When p is a pointer, the result of p++ or ++p is a pointer value which
can of course be dereferenced. Why would you think that only lvalues
can be dereferenced? The '*' indirection operator is applied to
expressions, not just lvalues.
| Quote: | When it talks about Unary Operators, why doesn't the secA7.4 collect
both the prefix and postfix incrementation operators together?
|
The choice of presentation is up to the authors. We are not mind
readers nor responsible for their choices. Ask them. I'm not even sure
what your question means. Certainly in K&R1 (A.7.2 Unary Operators) the
++lvalue, lvalue--, lvalue++, and lvalue-- are about as close to each
other as is physically possible.
| Quote: |
int main(void)
{
char a[10] = {0}, *p = a;
/* a[0] = 'a'; a[1] = 'b'; */
/* *p = 'a'; *(p+1) = 'b'; */
/* *p = 'a'; *p++ = 'b'; p--; */
*p = 'a'; *++p = 'b'; p--;
return 0;
}
|
|
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sun May 20, 2007 9:11 am Post subject: Re: The result of ++ is not an lvalue? |
|
|
"lovecreatesbea...@gmail.com" <lovecreatesbeauty (AT) gmail (DOT) com> writes:
| Quote: | K&R2, both sec A7.3.4 Postfix Incrementation and secA.7.4.1 Prefix
Incrementation Operators say that "The result is not an lvalue". Is
this correct?
|
Absolutely.
| Quote: | I don't see an errata on these points. If below the p++
or ++p is not an lvalue, then *p++ or *++p is a syntax error.
|
No, the operand of the unary "*" operator doesn't need to be an
lvalue; it just needs to be a pointer value.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
| Back to top |
|
 |
jg Guest
|
Posted: Sun May 20, 2007 9:11 am Post subject: Re: The result of ++ is not an lvalue? |
|
|
On May 19, 10:48 pm, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.com> wrote:
| Quote: | K&R2, both sec A7.3.4 Postfix Incrementation and secA.7.4.1 Prefix
Incrementation Operators say that "The result is not an lvalue". Is
this correct? I don't see an errata on these points. If below the p++
|
Yes, the result is not an lvalue.
| Quote: | or ++p is not an lvalue, then *p++ or *++p is a syntax error.
|
No. That (p++) isn't an lvalue means that there is no way to
change (p++), and doesn't mean (p++) cannot be dereferenced.
Let's see p = 1, (p++) is also 1. This '1' cannot be changed
in the way that any variable is changed because this '1' does not
have lvalue. You can't do (p++) = 2, for example. |
|
| Back to top |
|
 |
Richard Heathfield Guest
|
Posted: Sun May 20, 2007 9:11 am Post subject: Re: The result of ++ is not an lvalue? |
|
|
Keith Thompson said:
<snip>
| Quote: | No, the operand of the unary "*" operator doesn't need to be an
lvalue; it just needs to be a pointer value.
|
....which must be of object or function type, and which must actually
point to an object or function.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www. |
|
| Back to top |
|
 |
Harald van D k Guest
|
Posted: Tue May 22, 2007 3:34 am Post subject: Re: The result of ++ is not an lvalue? |
|
|
Old Wolf wrote:
| Quote: | On May 21, 2:18 am, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
No. *(any_valid_pointer_expression) is an lvalue, whatever
the status of any_valid_pointer_expression itself.
Except when it doesn't designate an object (e.g. if
the any_valid_pointer_expression is pointing one off
the end of an array).
|
Even then, and rightly so. Just imagine, otherwise whether
static void inc(int *p) {
++*p;
}
is a constraint violation (remember, a diagnostic is required for
constraint violations) depends on what values of p will be passed to
it at runtime. |
|
| Back to top |
|
 |
|
|
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
|
|