Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Not really an lvalue" warnings



Marshall Clow wrote:
This expression:
    static_cast<const char *>(typeOfQ)
is not a variable, it is a expression.

Think of the difference between 'x' and '3' - one can be assigned to, the other cannot )
Googling for "rvalue" and "lvalue" will give more general information.

The left hand side of an assignment need only be an lvalue, not just a variable. For example:


int &foo();
void bar()
{
	foo() = 5;
}

is valid since the expression foo() is a valid lvalue.


Peter O'Gorman wrote: > put the cast on the right hand side of the assignment.

Actually, putting the static_cast on the right hand side should fail since const char * cannot be cast to char * without const_cast.

You can put a const_cast<char *> on the right hand side or a const_cast<const char *&> on the left hand side (but that looks strange).

Mark Wagner wrote:
> I know the difference between an lvalue and an rvalue.  My
> understanding is that "static_cast<const char *>(typeOfQ)" is
> functionally and semantically equivalent to "(const char *)typeOfQ"
> with the addition of compile-time checking to make sure the conversion
> is defined.

That's just it, the conversion char * -> const char * isn't defined for lvalues, at least not without explicitly throwing away the constness via const_cast.

--
Steve Checkoway


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >"Not really an lvalue" warnings (From: "Mark Wagner" <email@hidden>)
 >Re: "Not really an lvalue" warnings (From: Marshall Clow <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.