lkml.org 
[lkml]   [1999]   [Apr]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [OFFTOPIC] Re: A bit off-topic ... (fwd)
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)'.

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
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 ?:.

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.

--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://kki.net.pl/qrczak/
\__/ GCS/M d- s+:-- a22 C+++>+++$ UL++>++++$ P+++ L++>++++$ E->++
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP->+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-


-
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/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.021 / U:1.924 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site