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

With some discipline, it's possible to achieve the same level of security in C as in pretty much any other high-level language.

Some useful techniques: always strive for simplicity, use types to encapsulate data dependencies and enforce error checking (e.g. store the length and pointer of an array as part of a struct and use methods that perform bounds checks to modify or read from it -- granted, this style of programming can add overhead, but C is so fast to begin with that it rarely matters), don't use unsafe standard library functions, test rigorously, valgrind everything, use static code analysis tools.

Doing any of these things goes a long way to eliminate the vast majority of bugs specific to C, but unfortunately way too many C projects hardly do any of them. It can evidently be done, though, as there are some very robust C libraries out there.

See also djb's comments about qmail (http://cr.yp.to/qmail/guarantee.html).



The problem is that C requires positive effort, above the baseline, to have those guarantees.

Any system which relies on positive human effort is more likely to fail than a system which simply sets a higher baseline.

You can be safe on a motorbike if you are very careful, avoid dangerous conditions, drive more slowly than you want and practice extreme care around cars. You are still more likely to die. The baseline is simply lower and, when things do go wrong, you have less safety buffer than someone in a car.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: