[Bug java/14818] gcj: boolean value changes with -Os

ovidr at users dot sourceforge dot net gcc-bugzilla@gcc.gnu.org
Fri Apr 2 04:02:00 GMT 2004


------- Additional Comments From ovidr at users dot sourceforge dot net  2004-04-02 04:02 -------
Here is another phenomenon:

>From the following class,

If you put
int i = b ? 1 : 0;
before the 
System.out.println("1 - now: " + b);

it is wrong. Result:
1 - now: false
i is: 0
2 - now: true
3 - is i > 0? true

(i is not > 0).

But, if you put the println first, the result is corrent. (3 - is i > 0? 
false).

Must use -Os: gcj --main=gc -Os gc.java

---

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class gc
{
  static public void main (String[] s)
  {
   bla(false);
  }

  static void bla(boolean b) {
    int i = b ? 1 : 0;
    System.out.println("1 - now: " + b);

    System.out.println("i is: " + i);

    try {
      Socket socket = new Socket("localhost", 8888);
    } catch (IOException e) {
      System.out.println("2 - now: " + b);
      bla2(i > 0);
    }
  }

  static void bla2(boolean b) {
    System.out.println("3 - is i > 0? " + b);
  }

}

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14818



More information about the Java-prs mailing list