Code Comments
Programming Forum and web based access to our favorite programming groups.Dave Hansen wrote: > > I believe the syntax is legal. Legal where? In C? No, it is not. > It just doesn't do what the OP wanted > it to. It doesn't do anything. It is illegal in C. > Consider that it parses as > > (1>0)?(aa):(b=10); But it doesn't parse like that in C. > Change it to 1<0?aa:b=10; and see the result... The result will be the same: a diagnostic message triggered by the attempt to assign to a non-lvalue. -- Best regards, Andrey Tarasevich
Post Follow-up to this messageAndrey wrote: ) Richard wrote: ) > ... )> But (c?x:y)=v; )> I dont really know what to say. ) ) Is there any reason why you believe that the property of "being an ) lvalue" should be necessarily lost in the process of selection from two ) lvalues of the same type? ) ) I mean I'm OK personally with the way it works in C. I just like to know ) what is it exactly in '(c?x:y)=v' that triggers a "I don't really know ) what to say" reaction from some people. Well then why not also make it possible for functions (that return pointers) to be lvalues ? returnspointertostruct(foo)->bar = baz; Or is that already legal ? SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT
Post Follow-up to this messageBartc wrote, On 31/03/08 18:45: > "Richard" <devr_@gmail.com> wrote in message > news:fsr52k$1id$1@registered.motzarella.org... > > ... > > You can argue the same way about using a?b:c as an rvalue. > > > a: You can write a = x without writing *(&a) = x You can't do 3 = x > a.b: You can write a.b = x without writing *(&a + offsetof b) = x You can't do 5.b or a.5 > (I think offsetof is more complex than that) > a->b: You can write a->b = x without writing *(&a + offsetof b) = x You can't do 5->b or b->5 > a[b]: You can write a[b] = x without writing *(a+b) = x Unless b is a pointer or array name you can't do 5[b] > a?b:c: You CAN'T write a?b:c = x without writing *(a ? &b : &c) = x You can do a?1:2 > So the mystery is why the compiler gives special dispensation to those oth er > forms when an lvalue is expected, but not the ?: form. > > Someone will say, for the same reason as a+b can't usually be an lvalue, b ut > I think ?: is a little different. I think you are wrong. Look at the fact that all of the other operators you mention *require* at least one of the operands to be an object but neither + nor ?: require and operand to be an object. Then you should see why it is natural for a?b:c = x to be wrong. -- Flash Gordon
Post Follow-up to this messageRichard wrote: > > because its not a macro? it returns a value. I dont know the legalise > words but it seems "obvious" enough to me, but again it might be because > I am tainted. Well, unary '*' operator is also not a macro. Yet it evaluates to an lvalue. Same for '[]' operator (by definition). Do you find this strange as well? -- Best regards, Andrey Tarasevich
Post Follow-up to this messageWillem wrote: > ) > ... > )> But (c?x:y)=v; > )> I dont really know what to say. > ) > ) Is there any reason why you believe that the property of "being an > ) lvalue" should be necessarily lost in the process of selection from two > ) lvalues of the same type? > ) > ) I mean I'm OK personally with the way it works in C. I just like to know > ) what is it exactly in '(c?x:y)=v' that triggers a "I don't really know > ) what to say" reaction from some people. > > Well then why not also make it possible for functions (that return > pointers) to be lvalues ? > > returnspointertostruct(foo)->bar = baz; > > Or is that already legal ? This is perfectly legal. It's just that has nothing to do with the function. Function still returns a non-lvalue. The left-hand side expression though (non-lvalue pointer)->bar is an lvalue. This why you can assign to it. What's illegal is this returnsstruct(foo).bar = baz; i.e. function returns a 'struct' in this case . -- Best regards, Andrey Tarasevich
Post Follow-up to this messageIn article <fsrc0v$4ov$3@registered.motzarella.org>, Richard <devr_@gmail.com> wrote: >because its not a macro? it returns a value. I dont know the legalise >words but it seems "obvious" enough to me, but again it might be because >I am tainted. Some other languages allow this. For example, I think Algol 68 allows IF a THEN b ELSE c FI := d; In C the number of contexts where an lvalue doesn't decay into an rvalue is very small, but I don't see anything inherently un-C-like about this case. -- Richard -- :wq
Post Follow-up to this messageAndrey Tarasevich <andreytarasevich@hotmail.com> writes: > Richard wrote: > > Well, unary '*' operator is also not a macro. Yet it evaluates to an > lvalue. Same for '[]' operator (by definition). Do you find this > strange as well? I think you have lost the track with all due respect. His original did produce an lvalue but a value. The "*" made it then an lvalue in the other case. I dont really know what we are aguing. There appears to be some sort of push for ?: to return an lvalue but it doesnt and never did.
Post Follow-up to this messagerichard@cogsci.ed.ac.uk (Richard Tobin) writes: > In article <fsrc0v$4ov$3@registered.motzarella.org>, > Richard <devr_@gmail.com> wrote: > > > > Some other languages allow this. For example, I think Algol 68 allows > > IF a THEN b ELSE c FI := d; > > In C the number of contexts where an lvalue doesn't decay into an rvalue > is very small, but I don't see anything inherently un-C-like about this > case. > > -- Richard And he can do it in C using pointers and *. I dont see the problem or the confusion here as far as the C language goes to be honest.
Post Follow-up to this messageIn article <fsrdh6$ikl$1@registered.motzarella.org>, Richard <devr_@gmail.com> wrote: >I think you have lost the track with all due respect. His original did >produce an lvalue but a value. I think the point was that * is an example of an operator that produces an lvalue, so it's not necessarily unreasonable for the ?: operator to. -- Richard -- :wq
Post Follow-up to this messageRichard wrote: > > I think you have lost the track with all due respect. His original did > produce an lvalue but a value. > > The "*" made it then an lvalue in the other case. > > I dont really know what we are aguing. I'm not really arguing. The way I interpreted your responses, it seemed that when someone said that in C++ '?:' would return an lvalue in this case, you essentially made it clear that you find it unnatural and/or illogical (again, the way I interpreted your responses). I just want to know what is it exactly that you find unnatural and/or illogical. -- Best regards, Andrey Tarasevich
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.