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

Everyone makes mistakes, but trying to write correct code is important. You have to be conscious of the consequences of what you write. You shouldn't rely on non-fixed-width types having specific lengths or on signed integer overflow, unless your code guarantees that things will work (preprocessor/static_assert checks against standard/compiler-specific properties). The worst offenders I see often is violating aliasing rules, especially in ways that could cause alignment issues.

In C, function isn't an object, you can't convert a function pointer as a void pointer and back, and use it. Yet I've seen that done many times, and it's probably safe on things that act as if they have a von Neumann architecture.

If I'm relying on implementation-dependent functionality, I try to make it so that whatever it is will fail to compile instead of having incorrect behaviour.




Better than you being aware, make sure your build system is aware - for example, compile your code with the maximum level of warnings and errors turned on, and don't commit it until you have resolved them all.


+1. Yet this should be done from the very start of the project.

Too often projects start in a permissive way, and then get released. At that point switching to strict way may become an unsurmountable task practically or politically.


Definitely, `-Wall -Wextra -pedantic` are always there, and only turning off individual ones if there's a good reason.


> In C, function isn't an object, you can't convert a function pointer as a void pointer and back, and use it.

It is not defined by the C standard, but POSIX requires it. So any environment (including the compiler) claiming POSIX conformance must support it.

Not sure how it works on Itanium though as, IIRC, function pointers there are twice as wide as normal pointers.


Plenty of platforms don't care about claiming POSIX conformance.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: