Home What is the "-->" operator in C++?
Reply: 0

What is the "-->" operator in C++?

user10078
1#
user10078 Published in September 19, 2018, 6:44 pm

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.

Here's the code:

#include <stdio.h>
int main()
{
    int x = 10;
    while (x --> 0) // x goes to 0
    {
        printf("%d ", x);
    }
}

I'd assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from?

share|improve this question
  • 425
    Or even just proper spacing... I don't think I've ever seen a space between the variable and either ++ or -- before... – Matthew Scharley Oct 29 '09 at 7:09
  • 969
    This "goes to" operator can be reverted ( 0 <-- x ). And also there is a "runs to" operator ( 0 <---- x ). Geez, the funniest thing I've ever heard of c++ syntax =) +1 for the question. – SadSido Oct 29 '09 at 7:27
  • 186
    Funnily enough, although the interpretation is very wrong, it does describe what the code does correctly. :) – Noldorin Nov 11 '09 at 13:51
  • 715
    Imagine the new syntax possibilities: #define upto ++<, #define downto -->. If you're feeling evil, you can do #define for while( and #define do ) { (and #define done ;}) and write for x downto 0 do printf("%d\n", x) done Oh, the humanity... – Chris Lutz Mar 4 '10 at 7:07
  • 57
    Opens the possibility of a whole new expressive way of coding, well worth sacrificing a few compiler warnings for: bool CheckNegative(int x) { return x<0 ? true :-( false ); } – ttt May 28 '12 at 11:12

21 Answers 21

active oldest votes
up vote 7554 down vote accepted
+50
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.466945 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO