comp.lang.c
[Top] [All Lists]

Re: ?: as an lvalue

Subject: Re: ?: as an lvalue
From: Andrey Tarasevich
Date: Mon, 31 Mar 2008 13:29:37 -0700
Newsgroups: comp.lang.c


lawrence.jones@xxxxxxxxxxx wrote:
...
Because b and c are two distinct objects that can have different types,
which makes the type of any resulting lvalue somewhat problematic.
...

Yes, it does. But when the second and the third operand have different (more precisely: non-compatible) types, there are quite a few things related to '?:' that are "problematic". The "lvalue" issue is just one of them. I we approach all of these issues with the same degree of pessimism, then we should probably prohibit '?:' operator entirely.

A more concrete example: in C language the '?:' operator can be applied to structures and unions. Of course, it is required that the second and the third operand have the same type (more precisely: compatible types). Needless to say, even though the result is not an lvalue, the idea to allow '?:' with structures immediately runs into the very same type-compatibility issues you are referring to. Still, it is perfectly legal in C to apply '?:' to structures. This illustrates the fact that in the process of language evolution the type-compatibility issue in '?:' has not been seen as a reason to discard a feature.

--
Best regards,
Andrey Tarasevich

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy