Lint and Static Analysis#

Lint and static-analysis tools inspect source code without running the program. They can catch suspicious code, style problems, missing initialization, unused variables, and other issues that deserve attention.

The current course syllabus, assignment instructions, programming standards, and applicable CSN or college policies take precedence over anything on this website.

Use these tools as a second check. They do not replace compiling with g++ $CXXFLAGS, running the program, reading the assignment instructions, or following the current syllabus.

lint#

Bellagio provides a custom lint macro for course use. This tool is specific to Bellagio; you should not expect to find the same lint command on your own computer or on other Linux systems.

The lint macro invokes, combines, filters, and orders output from cpplint and cppcheck so the most useful messages are easier to read.

Run it on one source file:

lint main.cpp

Run it on several source files:

lint *.cpp

Read the first message first. Later messages may be caused by an earlier issue. If lint reports a problem, inspect the code before changing it. A tool message is a clue, not a substitute for understanding the program.

If you are working on your own computer and the lint command is not available, use cppcheck and cpplint directly or compile and test your work on Bellagio.

cppcheck#

cppcheck looks for possible bugs and unsafe code patterns in C and C++ programs.

Run it on one source file:

cppcheck --enable=all --std=c++14 --suppress=missingIncludeSystem main.cpp

Run it on several source files in the current directory:

cppcheck --enable=all --std=c++14 --suppress=missingIncludeSystem *.cpp

The --std=c++14 option tells cppcheck to use the course language standard. The --suppress=missingIncludeSystem option reduces noise about system header files that may not be visible to the tool.

A cppcheck warning is not automatically a grading deduction, but it is a sign that you should inspect that part of the program.

cpplint#

cpplint checks C++ style. It may report style rules that differ from course standards, so treat its output as advisory. The assignment instructions, course programming standards, and syllabus take precedence.

Run it on one source file:

cpplint main.cpp

Run it on several source files:

cpplint *.cpp

If cpplint reports a header or copyright warning that conflicts with the course-required header comment, follow the course-required header comment.

If you want to ignore that specific cpplint category while checking the rest of the file, use:

cpplint --filter=-legal/copyright main.cpp

Good habits#

  • Compile first.
  • Run the program.
  • Run lint, cppcheck, or cpplint.
  • Fix one issue at a time.
  • Recompile after each meaningful change.
  • Do not make a change only because a tool suggested it. Understand the issue.
Note: The page you are viewing
is not sanctioned by CSN.