TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

Coding Rules

Rule Kind
Checked automatically with code checker
Severity Level


NameCheckedSynopsis
2.2#1 Checked automatically with code checker Comments shall not be nested.
2.3#1 Checked automatically with code checker Identifiers reserved by Standard C must not be used.
2.3#2 Checked automatically with code checker Identifiers shall not use more than the maximum number of characters required for unique identification as specified in the compliance matrix, described in section 1.7.
2.5.2#1 Checked automatically with code checker Only ANSI defined escape sequences shall be used.
2.5.4#1 String literals must have a formally defined value.
6#1 Checked automatically with code checker Make implicit conversions explicit.
6.2#1 Checked automatically with code checker Since conversion between signed and unsigned integral types involves implementation defined behaviour, signed and unsigned data items shall not be mixed within the same expression.
6.2#2 Use unsigned only where necessary.
6.3#1 Checked automatically with code checker Values shall not be implicitly converted to a narrower type.
6.3#2 Checked automatically with code checker Floating values should not be converted to integral types except through use of standard library routines.
6.3#3 Checked automatically with code checker Conversion of integral values to floating types should be avoided since loss of precision can occur.
6.4#1 Checked automatically with code checker Mixed precision arithmetic should be avoided if possible.
6.5#1 Checked automatically with code checker Mixed type arithmetic should be avoided.
6.5#2 Checked automatically with code checker Array indices must be within bounds.
6.6#1 Checked automatically with code checker Pointer to and from integer conversions shall not be used.
6.9#1 Checked automatically with code checker Pointers must not be cast to have potentially stricter alignment.
6.9#2 Checked automatically with code checker Pointers should not be type cast in general.
7#1 Checked automatically with code checker Expressions which either mix operators from the set >, >=, <, <=, ==, !=, with operators from the set <<, >>, ^, &, |, &&, || or which use two or more distinct operators from the latter set shall be fully parenthesised and make no use of the C precedence rules.
7#2 Checked automatically with code checker Expressions shall not contain multiple side-effects due either to the same identifier being modified more than once, or due to the same identifier being modified and accessed.
7#3 Checked automatically with code checker Expressions containing multiple function references should be avoided due to the possibility of side-effects occurring in an undefined order.
7.2#1 Checked automatically with code checker Void expressions have no value and must not be used in other expressions.
7.2#2 Checked automatically with code checker Constant expressions must not lead to division by zero.
7.2#3 Checked automatically with code checker The value of an incomplete 'union' must not be used.
7.2#4 Checked automatically with code checker The value of an incomplete 'struct' must not be used.
7.3.4#1 Checked automatically with code checker The increment and decrement operators should not be mixed with prefix forms in the same expression.
7.4.5#1 Checked automatically with code checker Unary minus shall not be applied to an unsigned expression.
7.4.8#1 Checked automatically with code checker sizeof shall not be applied to an expression with side-effects.
7.4.8#2 Checked automatically with code checker Wherever possible, use sizeof entity; rather than sizeof (type);
7.5#1 Checked automatically with code checker Expressions shall not be cast to the same type.
7.5#2 Checked automatically with code checker Explicit casting from and to any other type from void * is forbidden.
7.5#3 Checked automatically with code checker Avoid explicit casting where possible.
7.8#1 The right operand of a shift operator in a constant expression must not be negative or imply too large a shift.
7.8#2 Checked automatically with code checker The left operand of a shift operator must not be signed.
7.8#3 Left shifts in constant expressions shall not be such as to truncate any bits from the result.
7.9#1 Checked automatically with code checker The operands of relational operators should be parenthesised unless both are simple values, identifiers, or function calls.
7.10#1 Checked automatically with code checker Floating point expressions shall not be compared using either the == or != operators.
7.10#2 Checked automatically with code checker The operands of equality operators should be parenthesised unless both are simple values, identifiers, or function calls.
7.14#1 Checked automatically with code checker The right-hand operand of the logical AND operator shall not contain any side-effects because it is conditionally executed.
7.14#2 Checked automatically with code checker The operands of logical AND should be parenthesised unless both are simple values, identifiers, or function calls.
7.15#1 Checked automatically with code checker The right-hand operand of the logical OR operator shall not contain any side-effects because it is conditionally executed.
7.15#2 Checked automatically with code checker The operands of logical OR shall be parenthesised unless both are simple values, identifiers, or function calls.
7.16#1 Checked automatically with code checker The second and third operands of the conditional operator shall not contain side-effects because they are conditionally executed.
7.16#2 Checked automatically with code checker Use parentheses to improve readability of the conditional operator.
7.16#3 Checked automatically with code checker The convenience of the conditional operator should be weighed against the clarity of the code.
7.18#1 Checked automatically with code checker The comma operator must be used only within a for statement or within macros.
7.18#2 Checked automatically with code checker In general, the comma operator should be avoided.
7.19#1 Arithmetic operations on constant expressions must not lead to wrapround
8#1 Checked automatically with code checker Any specifiers present should appear in the following order: typedef, storage-class-specifier, type-specifier.
8.1#1 Checked automatically with code checker The address of an array declared with register is undefined and shall not be used.
8.1#2 Checked automatically with code checker Since auto is almost always redundant it shall be omitted to avoid cluttering up declarations.
8.1#3 Checked automatically with code checker register is a hint to the compiler.
8.2#1 Checked automatically with code checker const and volatile, if present, should appear before other type-specifiers.
8.3#1 Use of a tag must agree with its declaration
8.3#2 Checked automatically with code checker The concept of union whereby different kinds of data can be manipulated in a single area of storage is allowed only as the solution to certain kinds of problem but caution is urged in its use.
8.3#3 Checked automatically with code checker Bit fields must be of type int, signed or unsigned int only.
8.3#4 Checked automatically with code checker Do not use bit fields.
8.3#5 Checked automatically with code checker Signed bit-fields must not be of size 1.
8.3#6 Checked automatically with code checker The use of typedef to declare a struct or union is strongly recommended.
8.4#1 Checked automatically with code checker Only the first member of an enum may be explicitly initialised, if any, unless all items are explicitly initialised.
8.4#2 Checked automatically with code checker enum should be used with caution.
8.6.2#1 Checked automatically with code checker An array base type must not have function type.
8.6.2#2 Checked automatically with code checker Arrays must not be constructed from incomplete types.
8.6.3#1 Checked automatically with code checker Function prototype declarations and definitions of user-supplied functions shall be used
8.6.3#2 Checked automatically with code checker Function return types shall be explicitly given.
8.6.3#3 Checked automatically with code checker Pointers to functions should be declared and indirected using a typedef.
8.7#1 Checked automatically with code checker The initialiser for a struct, union or array bound, must be enclosed in braces.
8.7#2 Initialisers for a struct or union must have compatible type
8.7#4 Checked automatically with code checker For nested initialisers, the braces should match the structure.
8.9#1 Checked automatically with code checker An identifier declared as a typedef, must not be redeclared in an inner scope without a type specifier.
8.9#2 Checked automatically with code checker An identifier declared as a typedef, must not be redeclared as a member of a struct or union without a type specifier.
9.1#1 Checked automatically with code checker Statements must not be labelled.
9.1#2 Checked automatically with code checker Only a conventional case .. default construct may follow a switch statement.
9.1#3 Checked automatically with code checker A label should be on a separate line
9.2#1 Checked automatically with code checker A statement must have a side-effect, i.e., it must do something.
9.2#2 Checked automatically with code checker A null statement, if used, shall appear on a line by itself.
9.4#1 Checked automatically with code checker Controlling expressions shall not contain assignments.
9.4#2 Checked automatically with code checker To clarify the actual test performed in a selection statement, there should be an explicit comparison operator unless the compared object is of effectively 'Boolean' type.
9.4.1#1 Checked automatically with code checker Multiple choice constructs programmed using if ... else if ... shall have a "catch-all" clause.
9.4.1#2 Checked automatically with code checker The else and if should appear with the else indented to match the if above.
9.4.1#5 Checked automatically with code checker An if statement must be followed by a {..} construct even when only one statement, (null (;) or otherwise) is used.
9.4.1#6 Checked automatically with code checker An if statement must not lead to a degenerate comparison, for example the comparison of an unsigned quantity against a negative-valued constant.
9.4.2#1 Checked automatically with code checker All switch statements shall have a default clause, even if that clause is empty.
9.4.2#2 Checked automatically with code checker Each case clause and default clause shall be terminated by a break statement unless empty.
9.4.2#3 Checked automatically with code checker The default clause should be the last entry in the switch statement.
9.4.2#5 Checked automatically with code checker The switch expression shall not contain the ">", ">=", "<", "<=", "==", "!=", "&&", "||" or "!" operators.
9.4.2#6 Checked automatically with code checker The switch expression shall contain at least one case label.
9.5#1 Checked automatically with code checker To clarify the actual test performed in an iteration statement, there should be an explicit comparison operator.
9.5.1#1 Checked automatically with code checker A while statement must be followed by a {..} construct.
9.5.2#1 Checked automatically with code checker A for statement must be followed by a {..} construct even if only one statement is used.
9.5.2#2 Checked automatically with code checker The use of floating point variables as loop variables is forbidden.
9.5.2#3 Checked automatically with code checker A control variable shall not be altered by the body of a for statement.
9.5.2#4 Checked automatically with code checker Only loop control variable expressions should appear in the for statement.
9.5.2#5 Checked automatically with code checker Use a "for" loop construction for an infinite loop.
9.6.1#1 Checked automatically with code checker The break statement should not be used to exit from an iteration statement, (for or while).
9.6.2#1 Checked automatically with code checker The continue statement shall not be used.
9.6.3#1 Checked automatically with code checker The address of an object of automatic storage shall not be returned.
9.6.3#2 Checked automatically with code checker There should only be one return statement in a function returning non-void and this should appear at the bottom of the function. There should be no return statement in a function returning void.
9.7#1 Checked automatically with code checker The goto statement is unstructured and shall not be used.
10.1#1 Checked automatically with code checker Function return types must not use const or volatile.
10.1#2 Checked automatically with code checker A parameter must not have void type.
10.1#3 Checked automatically with code checker Identifiers must be given for all or none of the parameters in a function prototype declaration.
10.1#4 A function return expression must be compatible with its implicitly or explicitly defined type. If a function has a non-void return type, then it must contain only com-patible return statements
10.1#5 Checked automatically with code checker main() must have a defined type of int (void) or int (int, char *[]).
10.1#6 Checked automatically with code checker Explicit use of exit is not recommended.
10.1#7 Checked automatically with code checker No attempt must be made to use the result of a function returning void.
10.1#8 Checked automatically with code checker No const qualified void function of any kind is allowed.
10.1#9 Checked automatically with code checker Identifiers in function definition and declaration should be the same.
10.2#1 Checked automatically with code checker A function declared locally must have no storage-class specifier other than 'extern'.
10.2#2 Checked automatically with code checker Functions should not be declared locally.
10.2#3 Checked automatically with code checker An external identifier declaration after a previous external declaration must not have a different type.
10.2#4 All array types shall be complete by the end of the compilation unit
11.1#1 Checked automatically with code checker Identifiers shall not be redeclared within nested scopes.
11.2#1 Objects must not have incomplete type and no linkage
11.2#2 Checked automatically with code checker Variables must not have both internal and external linkage.
11.2#3 Checked automatically with code checker Variables must not have more than one definition with external linkage.
11.2#4 Identifiers with internal linkage (static) must have complete type
12#1 Checked automatically with code checker All identifiers used in preprocessor directives shall be defined.
12#2 Checked automatically with code checker Avoid esoteric aspects of preprocessing such as token pasting, text after #else or #endif, or relying on macro argument substitution within string literals.
12.1#1 Checked automatically with code checker Trigraphs shall not be used.
12.1#2 Checked automatically with code checker Avoid writing two adjacent question marks anywhere within your source code.
12.3#1 Checked automatically with code checker Always enclose any instances of macro parameters within parentheses.
12.3#2 Checked automatically with code checker If a macro body contains any operator, enclose it within parentheses.
12.3#3 Checked automatically with code checker Do not use macros to redefine keywords.
12.3#4 Checked automatically with code checker Avoid defining macros with unbalanced brackets or parentheses.
12.3#5 Checked automatically with code checker Macros should behave like symbolic constants or functions, (as function-like macros).
12.3#6 Use const to provide typed constants in preference to #define where legal and appropriate to do so.
12.3#7 Checked automatically with code checker Use functions in preference to function-like macros unless performance is a genuine issue.
12.3#8 Checked automatically with code checker Defining a macro called defined or attempting to #undef it, is forbidden.
12.3#9 Checked automatically with code checker Attempting to #define or #undef any of __LINE__, __FILE__, __DATE__, __TIME__, or __STDC__ is forbidden.
12.3#10 Checked automatically with code checker A function-like macro must be supplied with its expected arguments.
12.3#11 Checked automatically with code checker Macro arguments must not contain a sequence of tokens which look like a preprocessor directive.
12.3.1#1 Checked automatically with code checker A macro shall not comprise both the "#" and "##" operators simultaneously.
12.3.2#1 Checked automatically with code checker The result of the "##" operator shall be a legal pre-processing token.
12.4#1 Checked automatically with code checker The #include directive must only be followed by a <...> or a "..." file sequence.
12.4#2 Checked automatically with code checker Use of the ' " \ or /* characters in the #include file sequence <...> or "...", is forbidden.
12.5#1 Checked automatically with code checker The defined macro must appear in the form 'defined(identifier)' or 'defined identifier'.
12.6#1 Checked automatically with code checker The #line directive shall specify a line number in the range 1 to 32767.
12.8#1 Checked automatically with code checker The #pragma directive shall not be used without sign-off according to local quality procedures.
12.9#1 Checked automatically with code checker The null preprocessor directive # should not be used.
13#1 Checked automatically with code checker Functions shall be restricted to have a maximum decision count prescribed in the appropriate compliance table as measured by a recommended tool unless there is specific sign-off according to local procedures to the effect that this does not prejudice the reliability of the code and does not inhibit satisfactory test coverage.
13#2 Checked automatically with code checker Functions shall be restricted to have a maximum static path count prescribed in the appropriate compliance table as measured by a recommended tool unless there is specific sign-off according to local procedures to the effect that this does not prejudice the reliability of the code and does not inhibit satisfactory test coverage.
13#3 Checked automatically with code checker Functions shall be restricted to have a maximum cyclomatic complexity.
14#1 Checked automatically with code checker The dynamic memory allocation functions malloc, realloc and calloc shall not be used directly.
14#2 Checked automatically with code checker The signal handling routine signal and the non-specific jump functions setjmp and longjmp shall not be used without specific sign-off according to local procedures.
14#3 Checked automatically with code checker None of the following functions should be used directly if possible: ungetc, fopen, fgetpos, ftell, gets, remove, rename, bsearch, qsort, time, date, clock, isalnum, isalpha, iscntrl, islower, isprint, isupper, perror, strerror, calloc, malloc, realloc, exit, fmod.
A.2.4#1 Checked automatically with code checker Only one identifier shall be declared on each source line.
A.2.5#1 Checked automatically with code checker Only one statement shall appear on each source line.
A.2.5#2 Checked automatically with code checker All control statements shall be fully brace enclosed.
A.2.5#3 A consistent style of indentation should be adopted
A.2.5#4 Braces should be indented to the same level as the control statement with which they are associated
A.3.1#2 Checked automatically with code checker Every header file shall use #ifndef .. #endif to prevent its body being #included multiple times.
A.5.1#1 Checked automatically with code checker C++ keywords must not be used as identifiers
C#1 Checked automatically with code checker Make sure enums are not mixed with other types
C#2 Checked automatically with code checker The #error directive should be used with caution.
C#3 Checked automatically with code checker Preprocessor directives should begin in column 1 and there should be no white space between the # and the directive keyword.