Reputation: 87
guys! Why i can't take address of "t" - variable ?
flygs->type == 'X' ? t = a_ib_u(u->us, 16) : (a_lowcasealph(&(t = a_ib_u(u->us, 16))));
\\a_ib_u returns *char, a_lowcasealph take **char argument
error: cannot take the address of an rvalue of type 'char *'
Upvotes: 0
Views: 1362
Reputation: 44340
The answer by @dbush have already explained the cause of the error.
I like to add that you can rewrite the code and get something much easier to understand and maintain. Like:
t = a_ib_u(u->us, 16);
if (flygs->type != 'X') a_lowcasealph(&t);
Upvotes: 5
Reputation: 225227
You're not actually taking the address of a variable here:
&(t = a_ib_u(u->us, 16))
What you have here is an expression which is the assignment operator, and whose value is the value assigned. This is not the same as taking the address of a variable. As was mentioned in the comments, a variable is an lvalue, while an expression involving one or more operators an rvalue. You can only take the address of an lvalue.
To get around this, you can use the comma operator:
flygs->type == 'X' ? t = a_ib_u(u->us, 16) :
a_lowcasealph(((t = a_ib_u(u->us, 16)), &t));
Note that you need an extra pair of parenthesis around the comma operator expression to prevent the comma from being interpreted as a separator for function arguments.
Upvotes: 1