This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: java/4022: ?: precedence is wrong.
- To: nobody at gcc dot gnu dot org
- Subject: Re: java/4022: ?: precedence is wrong.
- From: Daniel Jacobowitz <drow at mvista dot com>
- Date: 16 Aug 2001 06:56:01 -0000
- Cc: gcc-prs at gcc dot gnu dot org,
- Reply-To: Daniel Jacobowitz <drow at mvista dot com>
The following reply was made to PR java/4022; it has been noted by GNATS.
From: Daniel Jacobowitz <drow@mvista.com>
To: apbianco@redhat.com
Cc: gcc-gnats@gcc.gnu.org, mjr@anarcast.net
Subject: Re: java/4022: ?: precedence is wrong.
Date: Wed, 15 Aug 2001 23:46:49 -0700
On Tue, Aug 14, 2001 at 07:39:18PM -0000, apbianco@redhat.com wrote:
> >Description:
> Consider this test case:
>
> public class Test {
> public static void main(String[] args) {
> String s = null;
> System.out.println("foo" + s != null ? s : "");
> }
> }
>
> $ ./test
> null
>
> When enclosed in parentheses, it behaves normally:
>
> System.out.println("foo" + (s != null ? s : ""));
>
> $ ./test
> foo
I could be wrong, since my Java is rusty, but that's not the precedence
of ?:. + has lower precedence than !=. "foo" + s is not equal to
null, so s is printed, which is null.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer