Although this piece of code is not standard, gcc will compile it, and the result will be consistent with my code analysis. Unfortunately, I cannot interpret the output without any extra context. If I ignore backspaces, the output looks something like this:
C!o!r!s!i!...
To analyze the code, we start by formatting it a bit:
#include <stdio.h> char* _ ="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX"; int main(int l){ for(l+=7; l != putchar(010); ++l); // 010 = 8 -> backspace char if(*(++_)) main( *_ != 88 ? // *_ != 'X' ( putchar(*_ ^ 073) | putchar(33) ) & 1 : // 33 = '!' 0xffff2a8b); }
Here are a few things to note before we go any further:
- If putchar succeeds, it returns the char that was passed.
- In C, numbers starting with 0 are actually octal, not decimal. So 010 is indeed the decimal number 8.
Now note that whenever the _ pointer is displayed, it is XORed with the octal value 073. If we apply this on the entire line, we get:
cCorsixcxCorsicixCorscsixCorcrsixCocorsixCcCorsixc
This begins to resemble the result we saw earlier. We continue by analyzing a few more interesting lines:
for(l+=7; l != putchar(010); ++l);
The point of this line is the output of a number of inverse spaces. If l is 1, it gives out only one backspace. But, if it is equal to something else, a truck with glasses flies into landfills. The behavior depends on what is called main. At startup, it is always called with a value of 1 (I don’t know why).
Now consider the components of a recursive main call.
( putchar(*_ ^ 073) | putchar(33) ) & 1 :
This is the first possible branch. First, it displays one of the XORed characters, and then displays '!' char. If you look at bit pattern 33, you will notice that (x | 33) and 1 will always be evaluated at 1. Thus, in this case, we only output one inverse character in the for loop.
The second branch, on the other hand, is a bit more complicated, because the value passed to main is not 1. If you look closely at the program output, you will notice that it displays the load on the packages in some place on the line. Without context, I cannot say what the goal is.
Now that we have all the parts, rewrite the code:
#include <stdio.h> #define BIG_CONSTANT 42 // Not the actual value. int main () { char* str = "cCorsixcxCorsicixCorscsixCorcrsixCocorsixCcCorsixc"; putchar(8); char* c = str; while (*c != '\0') { if (*c != 'c') { // 'X' ^ 073 = 'c' putchar(*c); putchar('!'); putchar(8); } else { for (int i = 0; i < BIG_CONSTANT; ++i) putchar(8); } c++; } }
My C is a little rusty, so it cannot compile / run. This should still give you a good idea of what is happening.
EDIT: Well, I was a little late in sending my answer, and I only realized that my console was printing backspaces a bit literally, instead of just deleting characters. Therefore, I misinterpreted the conclusion. Therefore, as in the accepted answer, if you handle the backspaces correctly, it prints Corsix !.