Re: [OFFTOPIC] Re: A bit off-topic ... (fwd)

Arvind Sankar (arvinds@mit.edu)
Fri, 2 Apr 1999 09:08:57 -0500


On Fri, Apr 02, 1999 at 10:47:28AM +0200, Marcin 'Qrczak' Kowalczyk wrote:
> Thu, 1 Apr 1999, Alexander Viro pisze:
>
> > ?: has *higher* priority than =.
>
> Yes, but egcs-1.1.1/gcc/NEWS says that:
>
> The parsing of expressions such as `a ? b : c = 1' has changed from
> `(a ? b : c) = 1' to `a : b ? (c = 1)'.

Notice that it says it has changed for C++, which is different from C.

>
> I guess that this is because otherwise y ? x=1 : x=2 would mean
> (y ? (x=1) : x) = 2.
>
> ?: is normally not l-value, but a gcc extension makes it an l-value when
> both arguments are. = is always l-value. Standard compiler would give an

Again, = does _not_ yield an l-value in C. Further, the ?: returning an
l-value is a C++ feature, and a gcc extension to C. So if you say it's an
extension, you're talking about C.

> error, but gcc, blindly following priorities and allowing the extension,
> would compile it the way that is not probably expected. So they swapped
> the priorities when = is on the right side of ?:.

they _did not_.

>
> other compilers older gcc newer gcc
>
> x=a?b:c x=(a?b:c) x=(a?b:c) x=(a?b:c)
>
> a?x=b:c a?(x=b):c a?(x=b):c a?(x=b):c
>
> a?b:x=c (a?b:x)=c (a?b:x)=c a?b:(x=c)
> SEMANTIC ERROR
>
> Although they use "incorrect" priorities here, they don't break correct
> programs.
>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/