2 ms·
These are all just lints, not proof systems. The big problems in C are: * How big is it? * Who owns it? * Who locks it? Those are the problems which cause
by Animats 3y ago
These are all just lints, not proof systems.
The big problems in C are:
* How big is it?
* Who owns it?
* Who locks it?
Those are the problems which cause trouble after the program has first started to work at all.
These lints don't help with those problems.
- steveklabnik 3y agoWhile they cannot solve all problems, it is worth not allowing the perfect to be the enemy of the good. You are correct that these are huge problems that are not currently solvable, but that doesn't mean that using these tools is a bad thing.
- flohofwoe 3y agoAt least gcc -fanalyze and clang-tidy are "proper" static analyzers. Don't get confused about the clang-tidy name, it might have started as a simple linter, but it also includes all the clang analyzer checks (e.g. search for clang-analyzer here: https://clang.llvm.org/extra/clang-tidy/checks/list.html https://clang.llvm.org/extra/clang-tidy/checks/list.html). And the clang static analyzer indeed does things like static ownership/lifetime tracking following the control flow as much as is possible at compile time. In code bases which haven't run through an analyzer yet it typically does need some handholding via asserts (for instance hinting that a pointer isn't expected to be null, otherwise you'll be swamped with false positives). Clang analyzer basically tells you things like "this statement here will cause a null pointer access if this seemingly unrelated function over there at the other end of the project is called with this specific argument, and here's how I arrived at that conclusion (...followed by dozens of "calling function x with y...", "entering loop with loop count z", "taking this if-branch because x is greater than y" etc... - in Xcode this is accompanied with a nice control flow visualization over the source code which makes it a bit easier to follow). Once a code base is static-analyzer-clean via "assert-hints", it will actually catch bugs at compile time which might be tricky to reproduce at runtime. Of course static analyzers are still only part of the solution (the "compile time part"), for runtime checks there are the various clang sanitizers.
- jvanderbot 3y agoI'd be suspicious of someone taking a stab at running ownership static verification before enabling basic sanity checks like those presented here. So. Maybe it qualifies as a "gentle introduction" since it's effectively step 1.
- bfrog 3y agoRight, people have created whole new languages to solve those
- pjmlp 3y agoYes, however many C and C++ developers to this day don't use any kind of lint checks, even though it was already invented in 1979 to deal with typical C flaws, by the group that created C in first place. Granted they could have made the language better, but I guess in the spirit of UNIX, they decided to have the separate pass be yet another tool. If someone is going with C, at very least they should already consider these, and eventually learn to adopt the real deal in terms of tooling for "safe" C.