Below code gives error on compilation in a C compiler
++(-i);
error: lvalue required as increment operand
It means that -i returns rvalue.
while code
++(+i);
don’t give any error . Why so? this link says that +i don’t result in lvalue.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is a glitch in your compiler. In C language all lvalues in expressions are converted to rvalues even before any operators are applied, with the exception of operands of
sizeof,&,++,--and left-hand sides of.and assignment (see 6.3.2/2)In other words, in C language
+imust produce an rvalue not because unary+supposedly produces an rvalue, but rather becauseiis converted to rvalue before that unary+even gets a chance to do its thing.For example, for an
int ivariable that holds value42, expression+iis fully equivalent to expression+42. The lvalueness ofiis lost and it gets turned into42before the semantics of unary+comes into play.Needless to say, in this case there’s no chance the result of unary
+can be an lvalue.