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

Most common in my world? Not checking return codes. Or check return codes and logging "there was an error" rather than using errno.

A couple uncommon ones: for (float x = 0.0; x < 3,5; x += 0.1) {...}

if (flag == TRUE) {...} (TRUE was #defined as 1 somewhere, but someone else set flag to a different non-zero value like -1, !0 or ~0.)



With the float for-loop, is the bug initializing the variable inside the loop declaration or is it the comma in "x < 3,5"?


I think you mean "declaring the variable inside the loop initialization", which is not a bug in C99 and not subtle anywhere else.

The intended bug is that 0.1, in floating-point, is not exactly 0.1. On x86 (and probably anything with IEEE-754 floating-point) the loop counter reaches 0.5 successfully, is a little bit high when it should have reached 1.0, remains high up to when it reaches slightly more than 2.2, and then suddenly becomes low when it should have reached 2.3, and continues to be slightly low and get progressively lower thereafter, all according to whether the sum is being rounded to a value that's slightly too high or slightly too low. The consequence is that the loop runs for an extra iteration with x ≈ 3.5, or 3,5 if you're from, say, Argentina.




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

Search: