| C User's Guide |
lintSource Code CheckerThis chapter explans how you can use the
lintprogram to check your C code for errors that may cause a compilation failure or unexpected results at runtime. In many cases,lintwarns you about incorrect, error-prone, or nonstandard code that the compiler does not necessarily flag.The
lintprogram issues every error and warning message produced by the C compiler. It also issues warnings about potential bugs and portability problems. Many messages issued bylintcan assist you in improving your program's effectiveness, including reducing its size and required memory.The
lintprogram uses the same locale as the compiler and the output fromlintis directed tostderr. This chapter is organized into the following sections:
- Basic and Enhanced lint Modes
- Using lint
- The lint Options
- lint Messages
- lint Directives
- lint Reference and Examples
Basic and Enhanced
lintModesThe
lintprogram operates in two modes:
- Basic, which is the default
- Enhanced, which includes everything done by basic
lint, as well as additional, detailed analysis of codeIn both basic and enhanced modes,
lintcompensates for separate and independent compilation in C by flagging inconsistencies in definition and use across files, including any libraries you have used. In a large project environment especially, where the same function may be used by different programmers in hundreds of separate modules of code,lintcan help discover bugs that otherwise might be difficult to find. A function called with one less argument than expected, for example, looks at the stack for a value the call has never pushed, with results correct in one condition, incorrect in another, depending on whatever happens to be in memory at that stack location. By identifying dependencies like this one and dependencies on machine architecture as well,lintcan improve the reliability of code run on your machine or someone else's.In enhanced mode,
lintprovides more detailed reporting than in basic mode. In enhanced mode,lint's capabilities include:
- Structure and flow analysis of the source program
- Constant propagations and constant expression evaluations
- Analysis of control flow and data flow
- Analysis of data types usage
In enhanced mode,
lintcan detect these problems:
- Unused #
includedirectives, variables, and procedures- Memory usage after its deallocation
- Unused assignments
- Usage of a variable value before its initialization
- Deallocation of nonallocated memory
- Usage of pointers when writing in constant data segments
- Nonequivalent macro redefinitions
- Unreached code
- Conformity of the usage of value types in unions
- Implicit casts of actual arguments.
Using
lintInvoke the
lintprogram and its options from the command line. To invoke lint in the basic mode, use the following command:
%lintfile1.cfile2.c
Enhanced
lintis invoked with the-Nlevelor-Ncheckoption. For example, you can invoke enhancedlintas follows:
%lint -Nlevel=3file1.cfile2.c
lintexamines code in two passes. In the first pass,lintchecks for error conditions within C source files; in the second pass, it checks for inconsistencies across C source files. This process is invisible to the user unlesslintis invoked with-c:
%lint -cfile1.cfile2.c
That command directs
lintto execute the first pass only and collect information relevant to the second--about inconsistencies in definition and use across file1.cand file2.c--in intermediate files named file1.lnand file2.ln:
% lsfile1.cfile1.lnfile2.cfile2.ln
This way, the
-coption tolintis analogous to the-coption tocc, which suppresses the link editing phase of compilation. Generally speaking,lint's command-line syntax closely followscc's.When the
.lnfiles arelinted:
%lintfile1.lnfile2.ln
the second pass is executed.
lintprocesses any number of.cor.lnfiles in their command-line order. Thus,
%lintfile1.lnfile2.lnfile3.c
directs
lintto check file3.cfor errors internal to it and all three files for consistency.
lintsearches directories for included header files in the same order ascc. You can use the-Ioption tolintas you would the-Ioption tocc. See Include FilesYou can specify multiple options to
linton the same command line. Options can be concatenated unless one of the options takes an argument or if the option has more than one letter:
%lint -cp -Idir1-Idir2file1.cfile2.c
- Execute the first pass only
- Perform additional portability checks
- Search the specified directories for included header files
linthas many options you can use to directlintto perform certain tasks and report on certain conditions.The
lintOptionsThe
lintprogram is a static analyzer. It cannot evaluate the runtime consequences of the dependencies it detects. Certain programs, for instance, may contain hundreds of unreachablebreakstatements that are of little importance, but whichlintflags nevertheless. This is one example where thelintcommand-line options and directives--special comments embedded in the source text--come in:
- You can invoke
lintwith the-boption to suppress all the error messages about unreachablebreakstatements.- You can precede any unreachable statement with the comment /
*NOTREACHED*/to suppress the diagnostic for that statement.The
lintoptions are listed below alphabetically. Severallintoptions relate to suppressinglintdiagnostic messages. These options are also listed in TABLE 6-6, following the alphabetized options, along with the specific messages they suppress. The options for invoking enhancedlintbegin with-N.
lintrecognizes manycccommand-line options, including-A,-D,-E,-g,-H,-O,-P,-U,-Xa,-Xc,-Xs,-Xt, and-Y, although-gand-Oare ignored. Unrecognized options are warned about and ignored.
-#Turns on verbose mode, showing each component as it is invoked.
-###Shows each component as it is invoked, but does not actually execute it.
-aSuppresses certain messages. Refer to TABLE 6-6.
-bSuppresses certain messages. Refer to TABLE 6-6.
-CfilenameCreates a
.lnfile with the file name specified. These.lnfiles are the product oflint's first pass only. filename can be a complete path name.
-cCreates a
.lnfile consisting of information relevant tolint's second pass for every.cfile named on the command line. The second pass is not executed.
-dirout=dirSpecifies the directory dir where the
lintoutput files (.lnfiles) will be placed. This option affects the-coption.
-err=warn
-err=warnis a macro for-errwarn=%all. See -errwarn=t.
-errchk=l(,l)Check structural arguments passed by value; Check portability to environment for which the size of long integers and pointers is 64 bits.
l is a comma-separated list of checks that consists of one or more of the following:
%allPerform all of
errchk's checks.
%nonePerform none of
errchk's checks. This is the default.
locfmtchkUse this option when you want
lintto checkprintf-like format strings during its first pass. Regardless of whether or not you use-errchk=locfmtchk,lintalways checks forprintf-like format strings in its second pass.
longptr64Check 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%longptr64Perform none of
errchk'slongptr64checks.The values may be a comma separated list, for example
-errchk=longptr64,structarg.The default is
-errchk=%none. Specifying-errchkis equivalent to specifying-errchk=%all.
no%structargPerform none of
errchk'sstructargchecks.
parenthesesUse this option to enhance the maintainability of code. If
-errchk=parenthesesreturns a warning, consider using additional parentheses to clearly signify the precedence of operations within the code.
signextThis option produces error messages when the normal ANSI/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=longptr64as well.
sizematchIssues a warning when a larger integer is assigned to a smaller integer. These warnings are also issued for assignment between same size integers that have different signs (unsigned int = signed int).
structargCheck structural arguments passed by value and report the cases when formal parameter type is not known.
-errfmt=fSpecifies the format of
lintoutput. f can be one of the following:macro,simple,src, ortab.
The default is
-errfmt=tab. Specifying-errfmtis equivalent to specifying-errfmt=tab.If more than one format is specified, the last format specified is used, and
lintwarns about the unused formats.
-errhdr=hEnables the reporting of certain messages for header files when used with
-Ncheck. h is a comma-separated list that consists of one or more of the following: dir,no%dir,%all,%none,%user.
The default is
-errhdr=%none. Specifying-errhdris equivalent to specifying-errhdr=%user.Examples:
%lint -errhdr=inc1 -errhdr=../inc2
checks used header files in directories
inc1and../inc2.
%lint -errhdr=%all,no%../inc
checks all used header files except those in the directory
../inc.
-erroff=tag(,tag)Suppresses or enables
linterror messages.t is a comma-separated list that consists of one or more of the following: tag,
no%tag,%all,%none.
The default is
-erroff=%none. Specifying-erroffis 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".
-errtags=aDisplays the message tag for each error message. a can be either
yesorno. The default is-errtags=no. Specifying-errtagsis equivalent to specifying-errtags=yes.Works with all
-errfmtoptions.
-errwarn=tIf the indicated warning message is issued,
lintexits 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 causeslintto exit with a fatal status if any warning except tag is issued. The following table lists the-errwarnvalues:
The default is
-errwarn=%none. If you specify-errwarnalone, it is equivalent to-errwarn=%all.
-FPrints the path names as supplied on the command line rather than only their base names when referring to the
.cfiles named on the command line.
-fdReports about old-style function definitions or declarations.
-flagsrc=fileExecutes
lintwith options contained in the file file. Multiple options can be specified in file, one per line.
-hSuppresses certain messages. Refer to TABLE 6-6.
-IdirSearches the directory dir for included header files.
-kAlter the behavior of
/* LINTED[message] */ directives orNOTE(LINTED(message)) annotations. Normally,lintsuppresses warning messages for the code following these directives. Instead of suppressing the messages,lintprints an additional message containing the comment inside the directive or annotation.
-LdirSearches for a
lintlibrary in the directory dir when used with-l.
-lxAccesses the
lintlibraryllib-lx.ln.
-mSuppresses certain messages. Refer to TABLE 6-6.
-Ncheck=cChecks 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.
The default is
-Ncheck=%none. Specifying-Ncheckis 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.
-Nlevel=nSpecifies the level of 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, or4.The default is-Nevel=2. Specifying-Nlevelis equivalent to specifying-Nlevel=4.
-Nlevel=1Analyzes single procedures. Reports unconditional errors that occur on some program execution paths. Does not do global data and control flow analysis.
-Nlevel=2The default. Analyzes the whole program, including global data and control flow. Reports unconditional errors that occur on some program execution paths.
-Nlevel=3Analyzes 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.
-Nlevel=4Analyzes 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=3with 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.
-nSuppresses checks for compatibility with the default
lintstandard C library.
-oxCauses
lintto create alintlibrary with the namellib-lx.ln. This library is created from all the.lnfiles thatlintused in its second pass. The-coption nullifies any use of the-ooption. To produce allib-lx.lnwithout extraneous messages, you can use the-xoption. The-voption is useful if the source file(s) for thelintlibrary are just external interfaces. Thelintlibrary produced can be used later iflintis invoked with-lx.By default, you create libraries in
lint's basic format. If you uselint's enhanced mode, the library created will be in enhanced format, and can only be used in enhanced mode.
-pEnables certain messages relating to portability issues.
-RfileWrite a
.lnfile to file, for use bycxref(1). This option disables the enhanced mode, if it is switched on.
-sConverts compound messages into simple ones.
-uSuppresses certain messages. Refer to TABLE 6-6. This option is suitable for running
linton a subset of files of a larger program.
-VWrites the product name and releases to standard error.
-vSuppresses certain messages. Refer to TABLE 6-6.
-WfileWrite a
.lnfile to file, for use bycflow(1). This option disables the enhanced mode, if it is switched on.
-xSuppresses certain messages. Refer to TABLE 6-6.
-XCC=aAccepts C++-style comments. In particular,
//can be used to indicate the start of a comment. a can be eitheryesorno. The default is-XCC=no. Specifying-XCCis equivalent to specifying-XCC=yes.
-Xarch=v9Predefines the
__sparcv9macro and searches for v9 versions of lint libraries.
-Xexplicitpar=a(SPARC) Directs
lintto recognize#pragma MPdirectives. a can be eitheryesorno. The default is-Xexplicitpar=no. Specifying-Xexplicitparis equivalent to specifying-Xexplicitpar=yes.
-Xkeeptmp=aKeeps temporary files created during
linting instead of deleting them automatically. a can be eitheryesorno. The default is-Xkeeptmp=no. Specifying-Xkeeptmpis equivalent to specifying-Xkeeptmp=yes.
-Xtemp=dirSets the directory for temporary files to dir. Without this option, temporary files go into
/tmp.
-Xtime=aReports the execution time for each
lintpass. a can be eitheryesorno. The default is-Xtime=no. Specifying-Xtimeis equivalent to specifying-Xtime=yes.
-Xtransition=aIssues warnings for the differences between K&R C and Sun ANSI/ISO C. a can be either
yesorno. The default is-Xtransition=no. Specifying-Xtransitionis equivalent to specifying-Xtransition=yes.
-yTreats every
.cfile named on the command line as if it begins with the directive/* LINTLIBRARY */or the annotationNOTE(LINTLIBRARY). Alintlibrary is normally created using the/* LINTLIBRARY */directive or theNOTE(LINTLIBRARY) annotation.
lintMessagesMost of
lint's messages are simple, one-line statements printed for each occurrence of the problem they diagnose. Errors detected in included files are reported multiple times by the compiler, but only once bylint, no matter how many times the file is included in other source files. Compound messages are issued for inconsistencies across files and, in a few cases, for problems within them as well. A single message describes every occurrence of the problem in the file or files being checked. When use of alintfilter (see lint Libraries) requires that a message be printed for each occurrence, compound diagnostics can be converted to the simple type by invokinglintwith the-soption.
Lint's messages are written tostderr.The Error and Warning Messages File, located in
/opt/SUNWspro/READMEs/c_lint_messages, contains all the C compiler error and warning messages and all thelintprogram's messages. Many of the messages are self-explanatory. You can obtain a description of the messages and, in many cases, code examples, by searching the text file for a string from the message that was generated.Options to Suppress Messages
You can use several
lintoptions to suppresslintdiagnostic messages. Messages can be suppressed with the-erroffoption, followed by one or more tags. These mnemonic tags can be displayed with the-errtags=yesoption.The following table lists the options that suppress
lintmessages.
lintMessage FormatsThe
lintprogram can, with certain options, show precise source file lines with pointers to the line position where the error occurred. The option enabling this feature is-errfmt=f.Under this option,lintprovides the following information:
- Source line(s) and position(s)
- Macro unfolding
- Error-prone stack(s)
For example, the following program,
Test1.c, contains an error.
Using
lintonTest1.cwith the option:
%lint -errfmt=src-Nlevel=2Test1.c
produces the following output:
The first warning indicates two source lines that are contradictory. The second warning shows the call stack, with the control flow leading to the error.
Another program,
Test2.c, contains a different error:
1 #define AA(b) AR[b+l]2 #define B(c,d) c+AA(d)34 int x=0;56 int AR[10]={1,2,3,4,5,6,77,88,99,0};78 main()9 {10 int y=-5, z=5;11 return B(y,z);12 }
Using
lintonTest2.cwith the option:
%lint -errfmt=macroTest2.c
produces the following output, showing the steps of macro substitution:
lintDirectivesPredefined Values
The following predefinitions are valid in all modes:
__sun__unix__lint__SUNPRO_C=0x510__`uname -s`_`uname -r` (example: __SunOS_5_7)__RESTRICT (-Xa and -Xt modes only)__sparc(SPARC)__i386(Intel)__BUILTIN_VA_ARG_INCR__SVR4__sparcv9 (-Xarch=v9)These predefinitions are not valid in
-Xcmode:
sununixsparc(SPARC)i386(Intel)lintDirectives
lintdirectives 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
lintdirectives in the form of source code annotations by including the filenote.h, for example:Lint shares the Source Code Annotations scheme with several other tools. When you install the Sun 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 Sun C source code checker,lint,also checks all the files in/usr/lib/noteand/opt/SUNWspro/<current-release>/notefor 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
lintdirectives along with their actions.
lintReference and ExamplesThis section provides reference information on
lint, including checks performed bylint,lintlibraries, andlintfilters.Checks Performed by
lint
lint-specific diagnostics are issued for three broad categories of conditions: inconsistent use, nonportable code, and questionable constructs. In this section, we review examples oflint's behavior in each of these areas, and suggest possible responses to the issues they raise.Consistency Checks
Inconsistent use of variables, arguments, and functions is checked within files as well as across them. Generally speaking, the same checks are performed for prototype uses, declarations, and parameters as lint checks for old-style functions. If your program does not use function prototypes,
lintchecks the number and types of parameters in each call to a function more strictly than the compiler.lintalso identifies mismatches of conversion specifications and arguments in[fs]printf()and[fs]scanf()control strings.
- Within files,
lintflags non-voidfunctions that "fall off the bottom" without returning a value to the invoking function. In the past, programmers often indicated that a function was not meant to return a value by omitting the return type:fun() {}. That convention means nothing to the compiler, which regardsfun()as having the return typeint. Declare the function with the return typevoidto eliminate the problem.- Across files,
lintdetects cases where a non-voidfunction does not return a value, yet is used for its value in an expression--and the opposite problem, a function returning a value that is sometimes or always ignored in subsequent calls. When the value is always ignored, it may indicate an inefficiency in the function definition. When it is sometimes ignored, it's probably bad style (typically, not testing for error conditions). If you need not check the return values of string functions likestrcat(),strcpy(), andsprintf(), or output functions likeprintf()andputchar(), cast the offending calls tovoid.lintidentifies variables or functions that are declared but not used or defined; used, but not defined; or defined, but not used. Whenlintis applied to some, but not all files of a collection to be loaded together, it produces error messages about functions and variables that are:Portability Checks
Some nonportable code is flagged by
lintin its default behavior, and a few more cases are diagnosed whenlintis invoked with-por-Xc. The latter causeslintto check for constructs that do not conform to the ANSI/ISO C standard. For the messages issued under-pand-Xc, see lint Libraries.
- In some C language implementations, character variables that are not explicitly declared
signedorunsignedare treated as signed quantities with a range typically from -128 to 127. In other implementations, they are treated as nonnegative quantities with a range typically from 0 to 255. So the test:
char c;c = getchar();if (c == EOF) ...
- where
EOFhas the value -1, always fails on machines where character variables take on nonnegative values.lintinvoked with-pchecks all comparisons that imply a plaincharmay have a negative value. However, declaringcas asignedcharin the above example eliminates the diagnostic, not the problem. That's becausegetchar()must return all possible characters and a distinctEOFvalue, so acharcannot store its value. We cite this example, perhaps the most common one arising from implementation-defined sign-extension, to show how a thoughtful application oflint's portability option can help you discover bugs not related to portability. In any case, declarecas anint.- A similar issue arises with bit-fields. When constant values are assigned to bit-fields, the field may be too small to hold the value. On a machine that treats bit-fields of type
intas unsigned quantities, the values allowed forint x:3range from 0 to 7, whereas on machines that treat them as signed quantities, they range from -4 to 3. However, a three-bit field declared typeintcannot hold the value 4 on the latter machines.lintinvoked with-pflags all bit-field types other thanunsigned intorsigned int. These are the only portable bit-field types. The compiler supportsint,char,short, andlongbit-field types that may beunsigned,signed, or plain. It also supports theenumbit-field type.- Bugs can arise when a larger-sized type is assigned to a smaller-sized type. If significant bits are truncated, accuracy is lost:
short s;long l;s = l;
lintflags all such assignments by default; the diagnostic can be suppressed by invoking the-aoption. Bear in mind that you may be suppressing other diagnostics when you invokelintwith this or any other option. Check the list in lint Libraries for the options that suppress more than one diagnostic.- A cast of a pointer to one object type to a pointer to an object type with stricter alignment requirements may not be portable.
lintflags:
int *fun(y)char *y;{return(int *)y;}
- because, on most machines, an
intcannot start on an arbitrary byte boundary, whereas acharcan. You can suppress the diagnostic by invokinglintwith-h, although, again, you may be disabling other messages. Better still, eliminate the problem by using the generic pointervoid *.- ANSI/ISO C leaves the order of evaluation of complicated expressions undefined. That is, when function calls, nested assignment statements, or the increment and decrement operators cause side effects when a variable is changed as a by-product of the evaluation of an expression, the order in which the side effects take place is highly machine-dependent. By default,
lintflags any variable changed by a side effect and used elsewhere in the same expression:
int a[10];main(){int i = 1;a[i++] = i;}Questionable Constructs
lintflags a miscellany of legal constructs that may not represent what the programmer intended. Examples:
- An
unsignedvariable always has a nonnegative value. So the test:
unsigned x;if (x < 0) ...
- always fails. The test:
unsigned x;if (x > 0) ...
- is equivalent to:
if (x != 0) ...
- This may not be the intended action.
lintflags questionable comparisons ofunsignedvariables with negative constants or0. To compare anunsignedvariable to the bit pattern of a negative number, cast it tounsigned:
if (u == (unsigned) -1) ...
Or use the
Usuffix:
if (u == -1U) ...
lintflags expressions without side effects that are used in a context where side effects are expected--that is, where the expression may not represent what the programmer intends. It issues an additional warning whenever the equality operator is found where the assignment operator is expected--that is, where a side effect is expected:
int fun(){int a, b, x, y;(a = x) && (b == y);}lintcautions you to parenthesize expressions that mix both the logical and bitwise operators (specifically,&,|,^,<<,>>), where misunderstanding of operator precedence may lead to incorrect results. Because the precedence of bitwise&, for example, falls below logical==, the expression:
if (x & a == 0) ...
lintLibrariesYou can use
lintlibraries to check your program for compatibility with the library functions you have called in it--the declaration of the function return type, the number and types of arguments the function expects, and so on. The standardlintlibraries correspond to libraries supplied by the C compilation system, and generally are stored in a standard place on your system. By convention,lintlibraries have names of the formllib-lx.ln.The
lintstandard C library,llib-lc.ln, is appended to thelintcommand line by default; checks for compatibility with it can be suppressed by invoking the-noption. Otherlintlibraries are accessed as arguments to-l. That is:
%lint -lxfile1.cfile2.c
directs
lintto check the usage of functions and variables infile1.candfile2.cfor compatibility with thelintlibraryllib-lx.ln. The library file, which consists only of definitions, is processed exactly as are ordinary source files and ordinary.lnfiles, except that functions and variables used inconsistently in the library file, or defined in the library file but not used in the source files, elicit no complaints.To create your own
lintlibrary, insert the directiveNOTE(LINTLIBRARY)at the head of a C source file, then invokelintfor that file with the-ooption and the library name given to-l:
%lint -oxfile1.cfile2.c
causes only definitions in the source files headed by
NOTE(LINTLIBRARY)to be written to the filellib-lx.ln. (Note the analogy oflint -otocc -o.) A library can be created from a file of function prototype declarations in the same way, except that bothNOTE(LINTLIBRARY)andNOTE(PROTOLIB(n))must be inserted at the head of the declarations file. If n is 1, prototype declarations are written to a library.lnfile just as are old-style definitions. If n is0, the default, the process is cancelled. Invokinglintwith-yis another way of creating alintlibrary. The command line:
%lint -y -oxfile1.cfile2.c
causes each source file named on that line to be treated as if it begins with
NOTE(LINTLIBRARY), and only its definitions to be written tollib-lx.ln.By default,
lintsearches forlintlibraries in the standard place. To directlintto search for alintlibrary in a directory other than the standard place, specify the path of the directory with the-Loption:
%lint -Ldir-lxfile1.cfile2.c
In enhanced mode,
lintproduces.lnfiles which store additional information than.lnfiles produced in basic mode. In enhanced mode,lintcan read and understand all.lnfiles generated by either basic or enhancedlintmodes. In basic mode,lintcan read and understand.lnfiles generated only using basiclintmode.By default,
lintuses libraries from the/usr/libdirectory. These libraries are in the basiclintformat. You can run amakefileonce, and create enhancedlintlibraries in a new format, which will enable enhancedlintto work more effectively. To run themakefileand create the new libraries, enter the command:
%cd /opt/SUNWspro/WS6/src/lintlib; make
where
/opt/SUNWspro/WS6is the installation directory. After themakefileis run,lintwill use the new libraries in enhanced mode, instead of the libraries in the/usr/libdirectory.The specified directory is searched before the standard place.
lintFiltersA
lintfilter is a project-specific post-processor that typically uses anawkscript or similar program to read the output oflintand discard messages that your project has deemed as not identifying real problems--string functions, for instance, returning values that are sometimes or always ignored.lintfilters generate customized diagnostic reports whenlintoptions and directives do not provide sufficient control over output.Two options to
lintare particularly useful in developing a filter:
- Invoking
lintwith-scauses compound diagnostics to be converted into simple, one-line messages issued for each occurrence of the problem diagnosed. The easily parsed message format is suitable for analysis by anawkscript.- Invoking
lintwith-kcauses certain comments you have written in the source file to be printed in output, and can be useful both in documenting project decisions and specifying the post-processor's behavior. In the latter instance, if the comment identifies an expectedlintmessage, and the reported message is the same, the message can be filtered out. To use-k, insert on the line preceding the code you wish to comment theNOTE(LINTED(msg))directive, where msg refers to the comment to be printed whenlintis invoked with-k.
- Refer to the list of directives in TABLE 6-7 for an explanation of what
lintdoes when-kis not invoked for a file containingNOTE(LINTED(msg)).
|
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |