12. september 2005

Fun with unary operators

Ok.. sooo while waiting for your experiments to finish you kinda have a lot of time for other things. So while eating lunch and trying, with a collegue of mine, to find any senarios where you would possibly have use of the unary + operator in C++ a new hobby was born!

What is the most useless but still aesthetically pleasing way of implementing a horizontal seperator in code without using comments (and without altering the calculations in the code, e.g. everything is the same as before with the new line inserted). The answer is ofcourse "fun with unary operators". From this little <hr> adventure a some what obscure kind of artform was born. A perfect mixture of beauty, uselessness and mindboggling results.

This is my first "art work" in this new art-genre so bear with me ;)
Ways of separating code with style

int main (int argc, char * argv[])
{
int x = 0;
int j = 0;
int a = 0;
int o = 0;
int lbs= 0;
int d = 0;

// Some cool horizontal lines
int i = + - + - + - + - + - + - + - + - + - + - + - + - + - + - a;
int n = + + + + + + + + + + + + + + + + + + + + + + + + + + + + a;

// Ahhh handles
int m = -+- -+- -+- -+- -+- -+- -+- -+- -+- -+- -+- -+- -+- -+- a;

// Get in shape with some weights..
int k = +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ a;

// For the fantasy people, some swords *ching*
int l = ++-- ++-- ++-- ++-- ++-- ++-- ++-- ++-- ++-- ++-- ++-- a;
int u = --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ --++ a;

// The man in your computer
int p = (o)-(o) ;
int y = d ;
int z = i---i ;

// And of course the geek with the glasses
int r = (o)+(o)-j ;
int q = d ;
int w = i---i ;

// And the glasses-geek after too many beers
int s = (x)+(x)-j ;
int h = d ;
int g = i---i ;

// The BIG weights
int e = (lbs)+----+(lbs);
std::cout << e;

std::cout << x << j << a << o << lbs << d << i;
std::cout << n << m << k << l << u << p << y;
std::cout << z << r << q << w << s << h << g;
}

.. and the mind-boggling part you ask?.. Ok who can tell me why the variable e is printed out containing the value "-4" when lbs is initalized as 0 above? Can you actually create a number from nothing? *spooky music*

And if that is not enough for you, how can the value for i printed out at the end be "-3" although the variables z,w,g all printed out the number "0"?

Engin ummæli: