Go to main content
Oracle® Developer Studio 12.6: C User's Guide

Exit Print View

Updated: July 2017

5.5 lint Directives

5.5.1 Predefined Values

Running lint predefines the lint token. See also the cc(1) man page for a list of predefined tokens.

5.5.2 Directives

lint directives in the form of /*...*/ are supported for existing annotations but will not be supported for future annotations. Directives in the form of source code annotations, NOTE(...), are recommended for all annotations.

Specify lint directives in the form of source code annotations by including the file note.h, for example:

#include <note.h>

lint shares the Source Code Annotations scheme with several other tools. When you install the Oracle Developer Studio C compiler, you also automatically install the file /usr/lib/note/SUNW_SPRO-lint, which contains the names of all the annotations that LockLint understands. However, the Oracle Developer Studio C source code checker, lint, also checks all the files in /usr/lib/note and the Oracle Developer Studio default location install-directory/prod/lib/note for all valid annotations.

You may specify a location other than /usr/lib/note by setting the environment variable NOTEPATH, as in:

setenv NOTEPATH $NOTEPATH:other_location

The following table lists the lint directives along with their actions.

Table 15  lint Directives
NOTE(ALIGNMENT(fname,n)) where n=1, 2, 4, 8, 16, 32, 64, 128
Makes lint set the following function result alignment in n bytes. For example, malloc() is defined as returning a char* or void* when it actually returns pointers that are word, or even doubleword, aligned.
Suppresses the following message:
  • improper alignment

This directive acts like the -v option for the next function.
Suppresses the following message for every argument but the first n in the function definition it precedes. Default is 0. For the NOTE format, n must be specified.
  • argument unused in function

Makes lint not check the mentioned arguments for usage (this option acts only for the next function).
Suppresses the following message for every argument listed in NOTE or directive.
  • argument unused in function

Suppresses complaints about constant operands for the conditional expression. Suppresses the following messages for the constructs it precedes.
constant in conditional context
constant operands to op: "!"
logical expression always false: op "&&"
logical expression always true: op "||"
Suppresses complaints about a null statement consequent on an if statement. This directive should be placed after the test expression and before the semicolon. This directive is supplied to support empty if statements when a valid else statement follows. It suppresses messages on an empty else consequent.
Suppresses the following messages when inserted between the controlling expression of the if and semicolon.
  • statement has no consequent: else

    when inserted between the else and semicolon;

  • statement has no consequent: if

Suppresses complaints about a fall through to a case or default labelled statement. This directive should be placed immediately preceding the label.
Suppresses the following message for the case statement it precedes. Also NOTE(FALLTHROUGH) or /* FALLTHROUGH */.
  • fallthrough on case statement

/*LINTED [msg]*/
Suppresses any intra-file warning (those issued by lint pass 1) except those dealing with unused variables or functions. Messages that require inter-file analysis and are issued by lint pass 2 cannot be suppress with the LINTED directive, and a warning message that the LINTED suppression directive was not used is usually given to indicate so. This directive should be placed on the line immediately preceding where the lint warning occurred. The -k option alters the way in which lint handles this directive. Instead of suppressing messages, lint prints an additional message, if any, contained in the comments. This directive is useful in conjunction with the -s option for post-lint filtering.
When -k is not invoked, suppresses every warning pertaining to an intra-file problem, except:
  • argument unused in function

  • declarations unused in block

  • set but not used in function

  • static unused

  • variable not used in function

    for the line of code it precedes. msg is ignored.

When -o is invoked, writes to a library .ln file, only definitions in the .c file it heads. This directive suppresses messages about unused functions and function arguments in this file.
At appropriate points, stops comments about unreachable code. This comment is typically placed just after calls to functions such as exit(2).
Suppresses the following messages for the closing curly brace it precedes at the end of the function.
  • statement not reached

    for the unreached statements it precedes;

  • fallthrough on case statement

    for the case it precedes that cannot be reached from the preceding case;

  • function falls off bottom without returning value

Treats the nth argument of the function definition it precedes as a [fs]printf() format string and issues the following messages for mismatches between the remaining arguments and the conversion specifications. lint issues these warnings by default for errors in the calls to [fs]printf() functions provided by the standard C library.
For the NOTE format, n must be specified.
  • malformed format strings

    for invalid conversion specifications in that argument, and function argument type inconsistent with format

  • too few arguments for format

  • too many arguments for format

When n is 1 and NOTE(LINTLIBRARY) or /* LINTLIBRARY */ is used, writes to a library .ln file only the function prototype declarations in the .c file it heads. The default is 0, which cancels the process.
For the NOTE format, n must be specified.
Same as NOTE(PRINTFLIKE(n)) or /* PRINTFLIKEn */, except that the nth argument of the function definition is treated as a [fs]scanf() format string. By default, lint issues warnings for errors in the calls to [fs]scanf() functions provided by the standard C library.
For the NOTE format, n must be specified.
Suppresses the usual checking for variable numbers of arguments in the following function declaration. The data types of the first n arguments are checked; a missing n is taken to be 0. The use of the ellipsis (...) terminator in the definition is suggested in new or updated code.
For the function whose definition it precedes, suppresses the following message for calls to the function with n or more arguments. For the NOTE format, n must be specified.
  • functions called with variable number of arguments