Fun C/C++ Hacks
Posted: Sat Feb 28, 2009 10:24 am
They might produce less readable code, but hacks are fun.
Just today, I was a little bored and was thinking of a way to embed statements (should be expressions, of course) directly into a 'while' condition. I came up with 'while (condition && (expression || true))'. It might not be faster, but it's cooler. 
Here's an example:-
Tell us about other fun hacks!
Here's an example:-
Code: Select all
//Absolutely fails for non-numbers.
int stringToInt(char *c)
{
int ret = *c - '0';
while (*++c && ((ret = (ret * 10) + (*c - '0')) || true));
return ret;
}