This Stack Overflow question discusses a curious C/C++ code snippet using `x --> 0` which functions as `x-- > 0`. It highlights a common coding 'trick' or obfuscation rather than a distinct operator. The question is a highly engaged discussion point for C/C++ developers regarding operator parsing and language quirks.
A starter prompt for Claude Code, what you'll need, and how to reach them.
You are a highly experienced C/C++ compiler and language expert. The user is asking about the `-->` construct in C/C++, specifically in the context of `while (x --> 0)`. Explain in detail how this parses as `x-- > 0`, referencing C/C++ standard rules for lexical analysis and operator precedence. Provide a concise, technically accurate, and easily understandable explanation. Include a minimal, self-contained C/C++ example demonstrating this behavior and explain the output. Ensure the explanation is suitable for a Stack Overflow answer aiming for clarity and correctness.
Post an answer directly to the Stack Overflow question.
“My answer provides a clear, concise explanation referencing the C/C++ standard regarding how `-->` is parsed as `x-- > 0`, which might be a good addition to this discussion.”
Open the original ↗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. I would assume this is also valid C since it works in GCC as well. Here's the code: #include <stdio.h> int main() { int x = 10; while (x --> 0) // x goes to 0 { printf("%d ", x); } } Output: 9 8 7 6 5 4 3 2 1 0 Where is this defined in the standard, and where has it come from? Tags: c++, c, operators, code-formatting, standards-compliance. (1,058,254 views, 26 answers)