Meaning of "an int value is expected"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Meaning of "an int value is expected"

ngogo
Hi,
I am recieving a bizzare compilation error on various parts of my code:
"an int value is expected".
It sometimes points to the line after return statements and sometimes after let statements. Here is part of the code where the lines the computer shouts with a pointing arrow:

function int multiply (int x, int y) {
                var int fixSign, toReturn;
               
                if (x=0|y=0){
                        return 0;
--> }
                let fixSign = false;
                if (x<0) {
--> let x = -x;
                        let fixSign = true;
                }

and:

        function int divide (int x, int y) {
               
                var int fixSign, toReturn;
               
                if (y=0){
                        do Sys.error(-1);
                }
-->
                let fixSign = false;
                if (x<0) {
--> let x = -x;

Any idea what the compiler wants?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Meaning of "an int value is expected"

cadet1620
Administrator
The errors are on the line after the line number in the error messages.

The Jack compiler is complaining about
  let fixSign = false;
because fixSign is an int and false is a boolean.

Also,
  if (x=0|y=0) {
doesn't do what you want because operator precedence and order of evaluation is undefined in Jack. This expression will be evaluated as
  ((x=0)|y)=0

--Mark

Loading...