Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Fortunately, with a few simple coding guidelines you can avoid major pitfalls.

1. Always do bit operations on unsigned types.

2. Never overflow signed types.

3. Always shift less than the type width. I can name architectures which implement large shifts in three distinct ways.

4. Know that most integers get promoted to int or unsigned, so you need an explicit cast to get 64 bits on most platforms. So 1ULL << 48 is okay, 1U << 48 is bad.

5. Treat unsigned int / unsigned long as contagious, just like float and double.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: