This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: java/4022: ?: precedence is wrong.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]