19.11.07
C’s “Goes To” Operator
Well it isn’t really an operator but this is a nice C code construct I ran into. It doesn’t seem to have any benefit except as a nice way to create a reverse loop:
int count = 100; while (count-->0) { //some work }
As I said I don’t think I’ll find any performance benefit for using this code snippet. On the other hand it is always fun to see the puzzled face other programmers have the first time they see the code.






Miroslav Mollov said,
March 4, 2008 at 3:51 pm
error: invalid operands of types ‘’ and ‘int’ to binary ‘operator 0 )
count
Guy said,
March 4, 2008 at 4:10 pm
Hi Miroslav,
I had an excess space there, it’s now fixed and should compile correctly.
thornza said,
March 25, 2008 at 1:49 pm
I don’t get it - why do you think this is an operator?…it is just the decrementing the count variable and testing whether it is greater than 0, so:
count–; //decrement
(count > 0) //and test
(count– > 0) (on one line)
Guy said,
March 25, 2008 at 4:20 pm
Of course it’s not a real C operator. This just a nice syntax that resembles the limit sign used in mathematics. When you got x–>0 you call it x goes to 0 so this looked to me similar to the same the C code which actually does something very close, so I called it the “goes to operator”.
Sorry for any misunderstanding it caused.