I’m trying to do something fairly simple. Of course it could be done with an extra line of code, but technically speaking, why does this not work?
int foo = 5; int *bar = &(--foo);
GCC compiler tells me "invalid lvalue in unary &"
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.
Because
--foois not an lvalue (so named since they typicaly appeared on the left of an asignment).It’s the same problem with:
If, for some bizarre reason, you need it on one line, just use:
If you think you need it in one instruction, think again. Even if you make such a horrible monstrosity (a), it will probably compile down to the same machine language sequence as that code snippet above.
(a)
int *bar = (--foo, &(foo));