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
   Website, Reference, Example Bugs
(Moderator: REAS)
   ++
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: ++  (Read 627 times)
js


++
« on: May 18th, 2004, 12:57pm »

I'm a fan of compact code à la C++, which means that I often use the ++ (increment) command. However there seems to be a bug for this command, either in the reference or in Processing itself. If I look at the example from the reference pages:
 
int a = 0;    // Sets "a" to 0  
int b = a++;  // Sets "b" to 1  
int c = b++;  // Sets "c" to 2  
 
it doesn't make sense in the typical (C++) definition, where the incrementation is done after each other command on the same line. This is also what happens when running the code - "a" will be 1 - "b" will be 1 - and "c" will be 0.
 
TomC

WWW
Re: ++
« Reply #1 on: May 18th, 2004, 1:43pm »


Pretty sure that's a bug in the reference.  
 
I read foo++ as "use foo and then increment foo", and ++foo as "increment foo and then use foo".
 
C++ and Java should be the same in this respect.
 
As I understand it, that code would work with the prefix increment (++a, and ++b).  So I guess the reference should either be...
 
Code:

int a = 0;    // Sets "a" to 0  
int b = a++;  // Sets "b" to 0, then "a" to 1  
int c = b++;  // Sets "c" to 0, then "b" to 1  

 
or:
 
Code:

int a = 0;    // Sets "a" to 0  
int b = ++a;  // Sets "a" to 1, then "b" to 1  
int c = ++b;  // Sets "b" to 2, then "c" to 2  

 
or:
 
Code:

int a = 0;    // Sets "a" to 0  
int b = ++a;  // Sets "a" to 1, then "b" to 1  
int c = b++;  // Sets "c" to 1, then "b" to 2  

 
Hope I got those right!
 
fry

WWW
Re: ++
« Reply #2 on: May 18th, 2004, 2:33pm »

yep, those are right, and it would just be a typo in the reference. java/c++ are identical on these points.
 
REAS


WWW
Re: ++
« Reply #3 on: May 18th, 2004, 9:56pm »

Yes, an error in the reference. I'm adding it to my reference corrections list.
 
+ Casey
 
REAS


WWW
Re: ++
« Reply #4 on: Jun 12th, 2004, 10:17am »

OK. The reference has been updated for both increment and decrement. Please check it out.
 
Pages: 1 

« Previous topic | Next topic »