What is the most hard to understand piece of C++ code you know?
The inverse square root implementation in Quake 3:
float InvSqrt (float x){
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
Update: How this works (thanks ryan_s)
I know it's C and not C++ but there is always the the International Obfuscated C Code Contest. I have seen some code there that would make your head spin.
Duff's Device (http://en.wikipedia.org/wiki/Duff%27s_device) give me nightmares:
strcpy(to, from, count)
char *to, *from;
int count;
{
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}
This was on reddit recently http://www.eelis.net/C++/analogliterals.xhtml
assert((o-----o
| !
! !
! !
! !
o-----o ).area == ( o---------o
| !
! !
o---------o ).area );