Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: ?: as an lvalue
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

Report this thread to moderator Post Follow-up to this message
Old Post
Andrey Tarasevich
04-01-08 12:19 AM


Re: ?: as an lvalue
Andrey 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

Report this thread to moderator Post Follow-up to this message
Old Post
Willem
04-01-08 12:20 AM


Re: ?: as an lvalue
Bartc 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

Report this thread to moderator Post Follow-up to this message
Old Post
Flash Gordon
04-01-08 12:20 AM


Re: ?: as an lvalue
Richard 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

Report this thread to moderator Post Follow-up to this message
Old Post
Andrey Tarasevich
04-01-08 12:21 AM


Re: ?: as an lvalue
Willem 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

Report this thread to moderator Post Follow-up to this message
Old Post
Andrey Tarasevich
04-01-08 12:22 AM


Re: ?: as an lvalue
In 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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard Tobin
04-01-08 12:22 AM


Re: ?: as an lvalue
Andrey 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
04-01-08 12:23 AM


Re: ?: as an lvalue
richard@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.

Report this thread to moderator Post Follow-up to this message
Old Post
Richard
04-01-08 12:23 AM


Re: ?: as an lvalue
In 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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard Tobin
04-01-08 12:24 AM


Re: ?: as an lvalue
Richard 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

Report this thread to moderator Post Follow-up to this message
Old Post
Andrey Tarasevich
04-01-08 12:25 AM


Sponsored Links




Last Thread Next Thread Next
Pages (10): « 1 2 3 [4] 5 6 7 8 9 » ... Last »
Search this forum -> 
Post New Thread

C archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 01:09 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.