How to convert from K & RC to ANSI C?

I am trying to execute the following code, which is a 1988 record of Obfuscated C Code Contest.

#define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ } 

From the record description, this code computes pi by looking at its own region. I successfully compiled it without changing the code. But when I completed, it gives me a value of 0.25, what I expect is 3.14. The code description says that it is in K & RC, and it does not work correctly in ANSI C without any changes. I think I should make these changes in order to execute it correctly. I have no previous experience with K & R C. So can someone help me change the code above to ANSI C or point out problems, if any. I am using Microsoft Visual Studio 2008 to accomplish this.

+6
c kr-c obfuscation
source share
2 answers

If you have GCC, compile the ' -traditional-cpp flag.

The difference is whether the sequence " -_ " translates to " - -F<00 " or " --F<00 ".

One space is crucial: this is the difference between double negation and pre-decrement.

+10
source share

change the line:

 #define _ F-->00 || F-OO--; 
+2
source share

All Articles