FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Bugs
   Software Bugs
(Moderator: fry)
   strange behaviour of int() inside parenthesis
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: strange behaviour of int() inside parenthesis  (Read 428 times)
baffo

WWW
strange behaviour of int() inside parenthesis
« on: Dec 12th, 2003, 1:46am »

Hello,
 
  while working with rev0067, I got strange compilation errors on a conditional. I have pared down the behaviour to this minimal piece of code: an int() conversion between parentheses creates unhappiness in a way I cannot understand. I am not a Java programmer, so maybe this is a very silly question. Anyway here is the example code.
 
int i = 1.0;  // can also be a float
 
void setup() {
  print((1==int(i)));
  print((int(i)==1));  // this line makes the compiler stop
        // with "expecting RPAREN, found '('"  
   
  print((int(i)));     // this one does too
  print((1));
}
 
  Of course the example code is completely pointless, but I was going for the minimal case.
 
  This has happened with Processing Alpha rev0067, under Windows 2000 Professional. There is nothing inside stderr.txt or the build folder.  
 

-- art is not where you think you're going to find it
mKoser

WWW Email
Re: strange behaviour of int() inside parenthesis
« Reply #1 on: Dec 12th, 2003, 3:15pm »

you need to use the java-syntax for this (i remember this problem being brought up before, but do not recall if it has been addressed yet!.. Ben?)
 
anyway, this syntax works:
Code:

float fx = 2.4;
int ix;
 
ix = (int)fx;    // instead of int(fx)

 
...so, your code from above would be (just moved around some parentheses):
Code:

int i = 1;  // can also be a float  
 
void setup() {  
  print((1==int(i)));  
  print(((int)i==1));  // this line makes the compiler stop  
   // with "expecting RPAREN, found '('"  
   
  print(((int)i));     // this one does too  
  print((1));  
}

 
hope that helps
Mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
fry


WWW
Re: strange behaviour of int() inside parenthesis
« Reply #2 on: Dec 12th, 2003, 4:42pm »

actually the int() stuff works fine, it's when there are double parentheses that causes the problem.
 
so if you change:
print((int(i)==1));
to
boolean isone = int(i) == 1;
print(isone);
i'm guessing it'd be ok.
 
apparently this is a difficult bug to fix in the parser (according to danm who wrote the parser code) because of the ambiguity on what parentheses mean, since we're supporting the int(x) syntax.
 
Pages: 1 

« Previous topic | Next topic »