cstyle.1

CSTYLE(1) General Commands Manual CSTYLE(1)

cstylecheck for some common stylistic errors in C source files

cstyle [-chpvCP] [-o construct[,construct…]] [file]…

cstyle inspects C source files (*.c and *.h) for common stylistic errors. It attempts to check for the cstyle documented in http://www.cis.upenn.edu/~lee/06cse480/data/cstyle.ms.pdf. Note that there is much in that document that be checked for; just because your code is cstyle-clean does not mean that you've followed Sun's C style. .

The following options are supported:

Check continuation line indentation inside of functions. Sun's C style states that all statements must be indented to an appropriate tab stop, and any continuation lines after them must be indented four spaces from the start line. This option enables a series of checks designed to find continuation line problems within functions only. The checks have some limitations; see , below.
Performs heuristic checks that are sometimes wrong. Not generally used.
Performs some of the more picky checks. Includes ANSI and rules, and tries to detect spaces after casts. Used as part of the putback checks.
Verbose output; includes the text of the line of error, and, for -c, the first statement in the current continuation block.
Ignore errors in header comments (i.e. block comments starting in the first column). Not generally used.
Check for use of non-POSIX types. Historically, types like and were used, but they are now deprecated in favor of the POSIX types , , etc. This detects any use of the deprecated types. Used as part of the putback checks.
construct[,construct…]
Available constructs include:
Allow doxygen-style block comments ( and ).
Allow splint-style lint comments (...).

The continuation checker is a reasonably simple state machine that knows something about how C is laid out, and can match parenthesis, etc. over multiple lines. It does have some limitations:

  1. Preprocessor macros which cause unmatched parenthesis will confuse the checker for that line. To fix this, you'll need to make sure that each branch of the statement has balanced parenthesis.
  2. Some cpp(1) macros do not require ;s after them. Any such macros be ALL_CAPS; any lower case letters will cause bad output.

    The bad output will generally be corrected after the next ;, , or .

Some continuation error messages deserve some additional explanation:
A multi-line statement which is not broken at statement boundaries. For example:
if (this_is_a_long_variable == another_variable) a =
    b + c;

Will trigger this error. Instead, do:

if (this_is_a_long_variable == another_variable)
    a = b + c;
For visibility, empty bodies for if, for, and while statements should be on their own line. For example:
while (do_something(&x) == 0);

Will trigger this error. Instead, do:

while (do_something(&x) == 0)
    ;
May 26, 2021 Debian