JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: C User's Guide
search filter icon
search icon

Document Information

Preface

1.  Introduction to the C Compiler

2.  C-Compiler Implementation-Specific Information

3.  Parallelizing C Code

4.  lint Source Code Checker

4.1 Basic and Enhanced lint Modes

4.2 Using lint

4.3 The lint Options

4.3.1 -#

4.3.2 -###

4.3.3 -a

4.3.4 -b

4.3.5 -C filename

4.3.6 -c

4.3.7 -dirout=dir

4.3.8 -err=warn

4.3.9 -errchk=l(, l)

4.3.10 -errfmt=f

4.3.11 -errhdr=h

4.3.12 -erroff=tag(, tag)

4.3.13 -errsecurity=v

4.3.14 -errtags=a

4.3.15 -errwarn=t

4.3.16 -F

4.3.17 -fd

4.3.18 -flagsrc=file

4.3.19 -h

4.3.20 -Idir

4.3.21 -k

4.3.22 -Ldir

4.3.23 -lx

4.3.24 -m

4.3.25 -m32|-m64

4.3.26 -Ncheck=c

4.3.27 -Nlevel=n

4.3.27.1 -Nlevel=1

4.3.27.2 -Nlevel=2

4.3.27.3 -Nlevel=3

4.3.27.4 -Nlevel=4

4.3.28 -n

4.3.29 -ox

4.3.30 -p

4.3.31 -Rfile

4.3.32 -s

4.3.33 -u

4.3.34 -V

4.3.35 -v

4.3.36 -Wfile

4.3.37 -XCC=a

4.3.38 -Xalias_level[=l]

4.3.39 -Xarch=amd64

4.3.40 -Xarch=v9

4.3.41 -Xc99[=o]

4.3.42 -Xkeeptmp=a

4.3.43 -Xtemp=dir

4.3.44 -Xtime=a

4.3.45 -Xtransition=a

4.3.46 -Xustr={ascii_utf16_ushort|no}

4.3.47 -x

4.3.48 -y

4.4 lint Messages

4.4.1 Options to Suppress Messages

4.4.2 lint Message Formats

4.5 lint Directives

4.5.1 Predefined Values

4.5.2 Directives

4.6 lint Reference and Examples

4.6.1 Diagnostics Performed by lint

4.6.1.1 Consistency Checks

4.6.1.2 Portability Checks

4.6.1.3 Questionable Constructs

4.6.2 lint Libraries

4.6.3 lint Filters

5.  Type-Based Alias Analysis

6.  Transitioning to ISO C

7.  Converting Applications for a 64-Bit Environment

8.  cscope: Interactively Examining a C Program

A.  Compiler Options Grouped by Functionality

B.  C Compiler Options Reference

C.  Implementation-Defined ISO/IEC C99 Behavior

D.  Supported Features of C99

E.  Implementation-Defined ISO/IEC C90 Behavior

F.  ISO C Data Representations

G.  Performance Tuning

H.  The Differences Between K&R Solaris Studio C and Solaris Studio ISO C

Index

4.3 The lint Options

The lint program is a static analyzer. It cannot evaluate the runtime consequences of the dependencies it detects. Certain programs, for instance, may contain hundreds of unreachable break statements that are of little importance, but which lint flags nevertheless. This is one example where the lint command-line options and directives—special comments embedded in the source text—come in:

The lint options are listed below alphabetically. Several lint options relate to suppressing lint diagnostic messages. These options are also listed in Table 4-8, following the alphabetized options, along with the specific messages they suppress. The options for invoking enhanced lint begin with -N.

lint recognizes many cc command-line options, including -A, -D, -E, -g, -H, -O, -P, -U, -Xa, -Xc, -Xs, -Xt, and -Y, although -g and -O are ignored. Unrecognized options are warned about and ignored.

4.3.1 -#

Turns on verbose mode, showing each component as it is invoked.

4.3.2 -###

Shows each component as it is invoked, but does not actually execute it.

4.3.3 -a

Suppresses certain messages. Refer to Table 4-8.

4.3.4 -b

Suppresses certain messages. Refer to Table 4-8.

4.3.5 -C filename

Creates a .ln file with the file name specified. These .ln files are the product of lint’s first pass only. filename can be a complete path name.

4.3.6 -c

Creates a .ln file consisting of information relevant to lint’s second pass for every .c file named on the command line. The second pass is not executed.

4.3.7 -dirout=dir

Specifies the directory dir where the lint output files (.ln files) will be placed. This option affects the -c option.

4.3.8 -err=warn

-err=warn is a macro for -errwarn=%all. See 4.3.15 -errwarn=t.

4.3.9 -errchk=l(, l)

Perform additional checking as specified by l. The default is -errchk=%none. Specifying -errchk is equivalent to specifying -errchk=%all. l is a comma-separated list of checks that consists of one or more of the following. For example, -errchk=longptr64,structarg.

Table 4-1 The -errchk Flags

Value
Meaning
%all
Perform all of -errchk’s checks.
%none
Perform none of -errchk’s checks. This is the default.
[no%]locfmtchk
Check for printf-like format strings during the first pass of lint. Regardless of whether or not you use -errchk=locfmtchk, lint always checks for printf-like format strings in its second pass.
[no%]longptr64
Check portability to environment for which the size of long integers and pointers is 64 bits and the size of plain integers is 32 bits. Check assignments of pointer expressions and long integer expressions to plain integers, even when explicit cast is used.
[no%]structarg
Check structural arguments passed by value and report the cases when formal parameter type is not known.
[no%]parentheses
Check the clarity of precedence within your code. Use this option to enhance the maintainability of code. If -errchk=parentheses returns a warning, consider using additional parentheses to clearly signify the precedence of operations within the code.
[no%]signext
Check for situations in which the normal ISO C value-preserving rules allow the extension of the sign of a signed-integral value in an expression of unsigned-integral type. This option only produces error messages when you specify -errchk=longptr64 as well.
[no%]sizematch
Check for the assignment of a larger integer to a smaller integer and issue a warning. These warnings are also issued for assignment between same size integers that have different signs (unsigned int gets a signed int).

4.3.10 -errfmt=f

Specifies the format of lint output. f can be one of the following: macro, simple, src, or tab.

Table 4-2 The -errfmt Flags

Value
Meaning
macro
Displays the source code, the line number, and the place of the error, with macro unfolding
simple
Displays the line number and the place number, in brackets, of the error, for one-line (simple) diagnostic messages. Similar to the -s option, but includes error-position information
src
Displays the source code, the line number, and the place of the error (no macro unfolding)
tab
Displays in tabular format. This is the default.

The default is -errfmt=tab. Specifying -errfmt is equivalent to specifying -errfmt=tab.

If more than one format is specified, the last format specified is used, and lint warns about the unused formats.

4.3.11 -errhdr=h

Enables lint to report certain messages for header files when you also specify -Ncheck. h is a comma-separated list that consists of one or more of the following: dir, no%dir, %all, %none, %user.

Table 4-3 The -errhdr Flags

Value
Meaning
dir
Report the -Ncheck messages for header files included from the directory dir
no%dir
Does not report the -Ncheck messages for header files included from the directory dir
%all
Checks all used header files
%none
Does not check header files. This is the default.
%user
Checks all used user header files, that is, all header files except those in /usr/include and its subdirectories, as well as those supplied by the compiler

The default is -errhdr=%none. Specifying -errhdr is equivalent to specifying -errhdr=%user.

Examples:

% lint -errhdr=inc1 -errhdr=../inc2

checks used header files in directories inc1 and ../inc2.

% lint -errhdr=%all,no%../inc

checks all used header files except those in the directory ../inc.

4.3.12 -erroff=tag(, tag)

Suppresses or enables lint error messages.

t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none.

Table 4-4 The -erroff Flags

Value
Meaning
tag
Suppresses the message specified by this tag. You can display the tag for a message by using the -errtags=yes option.
no%tag
Enables the message specified by this tag
%all
Suppresses all messages
%none
Enables all messages. This is the default.

The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.

Examples:

% lint -erroff=%all,no%E_ENUM_NEVER_DEF,no%E_STATIC_UNUSED

prints only the messages “enum never defined” and “static unused”, and suppresses other messages.

% lint -erroff=E_ENUM_NEVER_DEF,E_STATIC_UNUSED

suppresses only the messages “enum never defined” and “static unused”.

4.3.13 -errsecurity=v

Use the -errsecurity option to check your code for security loopholes.

v must be one of the following:

Table 4-5 The -errsecurity Flags

Value
Meaning
core
This level checks for source code constructs that are almost always either unsafe or difficult to verify. Checks at this level include:
  • Use of variable format strings with the printf() and scanf() family of functions

  • Use of unbounded string (%s) formats in scanf() functions

  • Use of functions with no safe usage: gets(), cftime(), ascftime(), creat()

  • Incorrect use of open() with O_CREAT

    Consider source code that produces warnings at this level to be a bug. The source code in question should be changed. In all cases, straightforward safer alternatives are available.

standard
This level includes all checks from the core level plus constructs that may be safe, but have better alternatives available. This level is recommended when checking newly-written code. Additional checks at this level include:
  • Use of string copy functions other than strlcpy()

  • Use of weak random number functions

  • Use of unsafe functions to generate temporary files

  • Use of fopen() to create files

  • Use of functions that invoke the shell

    Replace source code that produces warnings at this level with new or significantly modified code. Balance addressing these warnings in legacy code against the risks of destabilizing the application.

extended
This level contains the most complete set of checks, including everything from the Core and Standard levels. In addition, a number of warnings are generated about constructs that may be unsafe in some situations. The checks at this level are useful as an aid in reviewing code, but need not be used as a standard with which acceptable source code must comply. Additional checks at this level include:
  • Calls to getc() or fgetc() inside a loop

  • Use of functions prone to pathname race conditions

  • Use of the exec() family of functions

  • Race conditions between stat() and other functions

    Review source code which produces warnings at this level to determine if the potential security issue is present.

%none
Turns off -errsecurity checks

If you do not specify a setting for -errsecurity, the lint sets it to -errsecurity=%none. If you do specify -errsecurity but not an argument, the lint sets it to -errsecurity=standard.

4.3.14 -errtags=a

Displays the message tag for each error message. a can be either yes or no. The default is -errtags=no. Specifying -errtags is equivalent to specifying -errtags=yes.

Works with all -errfmt options.

4.3.15 -errwarn=t

If the indicated warning message is issued, lint exits with a failure status. t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none. Order is important; for example %all,no%tag causes lint to exit with a fatal status if any warning except tag is issued. The following table list the -errwarn values:

Table 4-6 The -errwarn Flags

tag
Cause lint to exit with a fatal status if the message specified by this tag is issued as a warning message. Has no effect if tag is not issued.
no%tag
Prevent lint from exiting with a fatal status if the message specified by tag is issued only as a warning message. Has no effect if tag is not issued. Use this option to revert a warning message that was previously specified by this option with tag or %all from causing lint to exit with a fatal status when issued as a warning message.
%all
Cause lint to exit with a fatal status if any warning messages are issued. %all can be followed by no%tag to exempt specific warning messages from this behavior.
%none
Prevents any warning message from causing lint to exit with a fatal status should any warning message be issued.

The default is -errwarn=%none. If you specify -errwarn alone, it is equivalent to -errwarn=%all.

4.3.16 -F

Prints the path names as supplied on the command line rather than only their base names when referring to the .c files named on the command line.

4.3.17 -fd

Reports about old-style function definitions or declarations.

4.3.18 -flagsrc=file

Executes lint with options contained in the file file. Multiple options can be specified in file, one per line.

4.3.19 -h

Suppresses certain messages. Refer to Table 4-8.

4.3.20 -Idir

Searches the directory dir for included header files.

4.3.21 -k

Alter the behavior of /* LINTED [message] */ directives or NOTE(LINTED(message)) annotations. Normally, lint suppresses warning messages for the code following these directives. Instead of suppressing the messages, lint prints an additional message containing the comment inside the directive or annotation.

4.3.22 -Ldir

Searches for a lint library in the directory dir when used with -l.

4.3.23 -lx

Accesses the lint library llib-lx.ln.

4.3.24 -m

Suppresses certain messages. Refer to Table 4-8.

4.3.25 -m32|-m64

Specifies the memory model for the program being analyzed. Also searches for lint libraries that correspond to the selected memory model (32-bit/64-bit).

Use -m32 to verify 32-bit C programs and -m64 to verify 64-bit C programs.

The ILP32 memory model (32-bit int, long, pointer data types) is the default on all Solaris platforms and on Linux platforms that are not 64-bit enabled. The LP64 memory model (64-bit long, pointer data types) is the default on Linux platforms that are 64-bit enabled. -m64 is permitted only on platforms that are enabled for the LP64 model.

Note that in previous compiler releases, the memory model, ILP32 or LP64, was implied by the choice of the -Xarch option. Starting with the Solaris Studio 12 compilers, this is no longer the case. On most platforms, just adding -m64 to the command line is sufficient for linting 64-bit programs.

See the sections following this list of lint options for more information on the predefined macros.

4.3.26 -Ncheck=c

Checks header files for corresponding declarations; checks macros. c is a comma-separated list of checks that consists of one or more of the following: macro, extern, %all, %none, no%macro, no%extern.

Table 4-7 The -Ncheck Flags

Value
Meaning
macro
Checks for consistency of macro definitions across files
extern
Checks for one-to-one correspondence of declarations between source files and their associated header files (for example, for file1.c and file1.h). Ensure that there are neither extraneous nor missing extern declarations in a header file.
%all
Performs all of -Ncheck’s checks
%none
Performs none of -Ncheck’s checks. This is the default.
no%macro
Performs none of -Ncheck’s macro checks
no%extern
Performs none of -Ncheck’s extern checks

The default is -Ncheck=%none. Specifying -Ncheck is equivalent to specifying -Ncheck=%all.

Values may be combined with a comma, for example, -Ncheck=extern,macro.

Example:

% lint -Ncheck=%all,no%macro

performs all checks except macro checks.

4.3.27 -Nlevel=n

Turns on enhanced lint mode by specifying the level of enhanced lint analysis for reporting problems. This option allows you to control the amount of detected errors. The higher the level, the longer the verification time. n is a number: 1, 2, 3, or 4. There is no default. If you do not specify -Nlevel, lint uses its basic analysis mode. If you specify -Nlevel without an argument, lint sets -Nlevel=4.

See 4.2 Using lint for an explanation of basic and enhanced lint modes.

4.3.27.1 -Nlevel=1

Analyzes single procedures. Reports unconditional errors that occur on some program execution paths. Does not do global data and control flow analysis.

4.3.27.2 -Nlevel=2

Analyzes the whole program, including global data and control flow. Reports unconditional errors that occur on some program execution paths.

4.3.27.3 -Nlevel=3

Analyzes the whole program, including constant propagation, cases when constants are used as actual arguments, as well as the analysis performed under -Nlevel=2.

Verification of a C program at this analysis level takes two to four times longer then at the preceding level. The extra time is required because lint assumes partial interpretation of the program by creating sets of possible values for program variables. These sets of variables are created on the basis of constants and conditional statements that contain constant operands available in the program. The sets form the basis for creating other sets (a form of constant propagation). Sets received as the result of the analysis are evaluated for correctness according to the following algorithm:

If a correct value exists among all possible values of an object, then that correct value is used as the basis for further propagation; otherwise an error is diagnosed.

4.3.27.4 -Nlevel=4

Analyzes the whole program, and reports conditional errors that could occur when certain program execution paths are used, as well as the analysis performed under -Nlevel=3.

At this analysis level, there are additional diagnostic messages. The analysis algorithm generally corresponds to the analysis algorithm of -Nlevel=3 with the exception that any invalid values now generate an error message. The amount of time required for analysis at this level can increase as much as two orders (about 20 to 100 time more slowly). In this case the extra time required is directly proportional to the program complexity as characterized by recursion, conditional statements etc. As a result of this, it may be difficult to use this level of analysis for a program that exceeds 100,000 lines.

4.3.28 -n

Suppresses checks for compatibility with the default lint standard C library.

4.3.29 -ox

Causes lint to create a lint library with the name llib-lx.ln. This library is created from all the .ln files that lint used in its second pass. The -c option nullifies any use of the -o option. To produce a llib-lx.ln without extraneous messages, you can use the-x option. The -v option is useful if the source file(s) for the lint library are just external interfaces. The lint library produced can be used later if lint is invoked with -lx.

By default, you create libraries in lint’s basic format. If you use lint’s enhanced mode, the library created will be in enhanced format, and can only be used in enhanced mode.

4.3.30 -p

Enables certain messages relating to portability issues.

4.3.31 -Rfile

Write a .ln file to file, for use by cxref(1). This option disables the enhanced mode, if it is switched on.

4.3.32 -s

Produce simple diagnostics with "warning:" or "error:" prefixes. By default lint buffers some messages to produce compound output.

4.3.33 -u

Suppresses certain messages. Refer to Table 4-8. This option is suitable for running lint on a subset of files of a larger program.

4.3.34 -V

Writes the product name and releases to standard error.

4.3.35 -v

Suppresses certain messages. Refer to Table 4-8.

4.3.36 -Wfile

Write a .ln file to file, for use by cflow(1). This option disables the enhanced mode, if it is switched on.

4.3.37 -XCC=a

Accepts C++-style comments. In particular, // can be used to indicate the start of a comment. a can be either yes or no. The default is -XCC=no. Specifying -XCC is equivalent to specifying -XCC=yes.


Note - You only need to use this option if you use -xc99=none. Under -xc99=all (the default), lint accepts comments which are indicated by //.


4.3.38 -Xalias_level[=l]

where l is one of any, basic, weak, layout, strict, std, or strong. See Table B-13 for a detailed explanation of the different levels of disambiguation.

If you do not specify -Xalias_level, the default of the flag is -Xalias_level=any. This means that there is no type-based alias-analysis. If you specify -Xalias_level but do not supply a level, the default is -Xalias_level=layout.

Be sure to run lint at a level of disambiguation that is no more strict than the level at which you ran the compiler. If you run lint at a level of disambiguation that is more strict than the level at which you compiled, the results will be difficult to interpret and possibly misleading.

See 4.6.3 lint Filters for a detailed explanation of disambiguation as well as a list of pragmas designed to help with disambiguation.

4.3.39 -Xarch=amd64

(Solaris Operating System) Deprecated. Do not use. See 4.3.25 -m32|-m64

4.3.40 -Xarch=v9

(Solaris Operating System) Deprecated. Do not use. See 4.3.25 -m32|-m64

4.3.41 -Xc99[=o]

The -Xc99 flag controls compiler recognition of the implemented features from the C99 standard (ISO/IEC 9899:1999, Programming Language -C).

o can be one of the following: all, none.

-Xc99=none turns off recognition of C99 features. -Xc99=all turns on recognition of supported C99 features.

Specifying -Xc99 without any arguments is the same as -Xc99=all.


Note - Though the compiler support-level defaults to the features of C99 listed in Table C-6 , the standard headers provided by Solaris software in /usr/include do not yet conform with the 1999 ISO/IEC C standard. If you encounter error messages, try using -Xc99=none to obtain the 1990 ISO/IEC C standard behavior for these headers.


4.3.42 -Xkeeptmp=a

Keeps temporary files created during linting instead of deleting them automatically. a can be either yes or no. The default is -Xkeeptmp=no. Specifying -Xkeeptmp is equivalent to specifying -Xkeeptmp=yes.

4.3.43 -Xtemp=dir

Sets the directory for temporary files to dir. Without this option, temporary files go into /tmp.

4.3.44 -Xtime=a

Reports the execution time for each lint pass. a can be either yes or no. The default is -Xtime=no. Specifying -Xtime is equivalent to specifying -Xtime=yes.

4.3.45 -Xtransition=a

Issues warnings for the differences between K&R C and Solaris Studio ISO C. a can be either yes or no. The default is -Xtransition=no. Specifying -Xtransition is equivalent to specifying -Xtransition=yes.

4.3.46 -Xustr={ascii_utf16_ushort|no}

This option enables recognition of string literals of the form U"ASCII_string" as an array of unsigned short int. The default is -Xustr=no which disables compiler recognition of U"ASCII_string string literals. "-Xustr=ascii_utf16_ushort enables compiler recognition of U"ASCII_string" string literals.

4.3.47 -x

Suppresses certain messages. Refer to Table 4-8.

4.3.48 -y

Treats every .c file named on the command line as if it begins with the directive /* LINTLIBRARY */ or the annotation NOTE(LINTLIBRARY). A lint library is normally created using the /* LINTLIBRARY */ directive or the NOTE(LINTLIBRARY) annotation.