Method Invocation: Argument Evaluation Order

Ranjit Mathew rmathew@hotmail.com
Wed Oct 16 01:19:00 GMT 2002


Hi,

     According to the JLS (section 15.12.4.2, "Evaluate Arguments")
while evaluating the arguments passed to a method invocation:

http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#45449

"The argument expressions are evaluated in order, from left to right..."

Therefore the following program should output (as it indeed
does with the Sun JDK 1.3.1):

a = 0
b = 1

But instead, with GCJ 3.2 on Solaris, it outputs:

a = 1
b = 1

The program in question is:
-------------------------- 8< ----------------------------
public class PreIncr
{
     private int i = 0;

     public static void main( String[] args)
     {
         new PreIncr( ).doIt( );
     }

     private void doIt( )
     {
         this.printAB( i, ++i);
     }

     private void printAB( int a, int b)
     {
         System.out.println( "a = " + a);
         System.out.println( "b = " + b);
     }
}
-------------------------- 8< ----------------------------

Isn't this a bug? Or am I missing something here?

Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/





More information about the Java mailing list