Hacker News new | past | comments | ask | show | jobs | submit login

My favourite C trick is -Dcontinue=break in the Makefile.

Sacrasm aside, I like (( x > 0 )&&( (x&(x-1)) == 0 )) trick to test if x is a power of two. But all arithmetic tricks like this need to be commented in detail, used rarely, and properly documented.

Edit: I've also used "-Dfor=if(0);else for" to make some ancient C++ compiler obey C++0x scoping rules for variables declared in initializer list of 'for' statement.




I remember using the `#define for if (0) else for` trick, too - was it with MSVC 98 by any chance?


Maybe, I don't remember. It was long ago.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: