Does anyone know how to obtain lint for Mac, Windows, and Linux? sudo port install lint
can't find it.
Asked
Active
Viewed 3.4k times
20
-
4Lint is pretty old, and pretty much everything lint used to warn about is now covered by actual compiler warnings. You might want to try something modern like [Cppcheck](http://cppcheck.sourceforge.net/) (which works great for C programs too). – Greg Hewgill Jul 30 '11 at 05:32
-
2You may need to enable optimizations to get "pretty much everything lint used to warn about'. Without optimizations, the compiler may skip the analysis that would discover the issues it can warn about. – luser droog Jul 30 '11 at 05:55
-
@GregHewgill, Is Cppcheck available only on Windows? If yes, any suggested alternatives for linux? – gokul_uf Mar 08 '16 at 20:30
-
@Gokul_uf: Of course not, just download the source tarball from sourceforge or clone the project from github. Cppcheck works on pretty much any platform that can compile C++ code. – Greg Hewgill Mar 08 '16 at 20:33
-
@gokul_uf `sudo apt-get install cppcheck` – arainchi May 05 '17 at 06:09
2 Answers
12
I've only seen lint for BSD. There's splint, however, a GPL lint rewrite, and it's available on most Linux distributions.

Bo Persson
- 90,663
- 31
- 146
- 203

Antti
- 11,944
- 2
- 24
- 29
-
1On Mavericks, `splint` complains about `osd.c:519:3: error: unknown type name '__pid_t'; did you mean 'pid_t'? __pid_t pid = getpid (); ^~~~~~~ pid_t /usr/include/sys/_types/_pid_t.h:30:31: note: 'pid_t' declared here typedef __darwin_pid_t pid_t; ^ 1 error generated.` during compilation/make step. Change that line to `pid_t pid = getpid ();` to compile/make on OS X Mavericks. – Agi Hammerthief Oct 03 '14 at 12:56
4
From the splint FAQ:
Splint supports most, but not all, of the C99 extensions to the ANSI C.
This implies that splint is alas not the same as lint. I've had personal experience with running splint on pieces of code like this:
for (int i; i < 100; i++)
/* Run code */
As declaration of a variable inside the for loop header is not permitted until C99, like in this example, splint will complain about this. Hence, I'm still looking for a good alternative to splint for Ubuntu.

gustafbstrom
- 1,622
- 4
- 25
- 44
-
1
-
@arainchi For the sake of the example and to avoid confusion, the definition should be omitted here in my opinion. It's the variable declaration that is the issue. – gustafbstrom May 04 '17 at 07:44
-
1@arainchi for completition, the code should be: ```c { int i; for (i = 0; i < 100; i++); } ``` – Daniele Tentoni Dec 01 '21 at 17:11