C++ fun: obfuscated "Hello world!"
Let's have a little fun in C++. The goal is to write an obfuscated version of the "Hello world!" program in C++. However, there are some rules (so it will be a bit harder):
[list=1][*]The program will be in ONE file -- main.cpp[*]Only standard C++ allowed. That is: console app that compiles and runs under Win, Linux, *NIX[*]No preprocessor usage, except for #include <...> -- that is, no obscure macros[*]Obfuscating by weirdly formatting the code doesn't count[*]You may use names as "foo", "goo" or "bar" to 'hide' the functionality of some construct[/list=1]
The idea is to use obscure/less known language features. The program has to write "Hello world!"(\n) to cout and exit. The use of the Standard Library is not only allowed, but encouraged. OS-specific functions are forbidden.
I will start with an entry that is not quite standard. A cookie to the first who tells me why :)
Code:
#include <iostream>
#include <string>
class base
{
public:
base(char c = 0x48):c_(c){b_ = new base(*this);}
base(const base& rhs)
{
int d[] = {-29, -7, 0, -3, 79, -87, 8, -3, 6, 8, 67, 23};
c_ = rhs.c_ - d[i++];
b_ = (i-12)?new base(*this):0;
}
~base()
{
using namespace std;
cout<<c_;
delete b_;
}
private:
char c_;
base *b_;
static int i;
};
int base::i = 0;
int main() // corrected from x_main to main: my mistake, thx to j0nas
{
base b;
return 0;
}
Enjoy!