Re: A question on string literals



Joe Wright <jwright@xxxxxxxxxxx> writes:
> Chris Torek wrote:
>>
> [ snip ]
>> Once you understand the idea of "object context" and "value context",
>> you simply have to memorize which operators have which context(s):
>> &foo - object context
>> sizeof foo - object (or maybe even "sizeof") context
>> foo + bar - two value contexts
>> foo = bar - one object context, one value context
>> ++foo - object context
>> and so on.
>>
> I know you Chris and I love you like a brother but given..
> int foo = 2, bar = 3;
>
> &foo - is the address of foo, a 'value' of type (int*)
> sizeof foo - is a value (4 at my house) of type (size_t)
> ++foo - is a value (now 3) of type (int)
>
> None of these have 'object' context as I see it. What are you trying
> to tell us here?

In "&foo", he's talking about the context in which the name "foo"
appears, not the entire expression. The argument to the unary "&"
operator must be an lvalue, so foo is in an "object context". Similarly,
the argument of unary "++" must be an lvalue.

He's mistaken about sizeof, which doesn't require an lvalue.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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.
.



Relevant Pages