home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlint1_0.zip / tlint1_0 / doc / lnt10man.txt < prev    next >
Text File  |  1996-02-05  |  63KB  |  2,168 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.                      LLIINNTT RReeffeerreennccee MMaannuuaall
  28.  
  29.  
  30.  
  31.  
  32.                                by
  33.  
  34.                          J. A. Gardner
  35.  
  36.                          Thinkage Ltd.
  37.                        85 McIntyre Drive
  38.                        Kitchener, Ontario
  39.                         Canada  N2R 1H6
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.                 Copyright 1995 by Thinkage Ltd.
  60.  
  61.  
  62.  
  63. Thinkage Ltd.                          LINT Reference Manual
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                      TTaabbllee ooff CCoonntteennttss
  71.  
  72.  
  73. 11.. IInnttrroodduuccttiioonn........................................................................................22
  74.  
  75. 22.. LLIINNTT DDiirreeccttiivveess..................................................................................33
  76.  
  77. 33.. LLIINNTT OOuuttppuutt..........................................................................................44
  78.     Message Classes........................................4
  79.     Output Grouping........................................6
  80.     Type Information.......................................7
  81.  
  82. 44.. LLIINNTT CCoonnvveennttiioonnss................................................................................99
  83.  
  84. 55.. UUnnuusseedd DDeeffiinniittiioonnss aanndd DDeeccllaarraattiioonnss........................................1100
  85.     Marking Symbols As Used...............................10
  86.  
  87. 66.. UUnnddeeffiinneedd oorr UUnnddeeccllaarreedd DDaattaa OObbjjeeccttss......................................1111
  88.  
  89. 77.. UUnnrreeaacchhaabbllee CCooddee..............................................................................1122
  90.     Marking Unreachable Code..............................12
  91.  
  92. 88.. FFuunnccttiioonn RReettuurrnn VVaalluueess..................................................................1133
  93.     Ignoring Return Values................................14
  94.  
  95. 99.. TTyyppee CChheecckkiinngg....................................................................................1155
  96.  
  97. 1100.. FFuunnccttiioonn DDeeccllaarraattiioonnss..................................................................1177
  98.     The #pragma varargs Directive.........................18
  99.     The #pragma argsused Directive........................19
  100.  
  101. 1111.. AAlltteerrnnaattee FFoorrmmss..............................................................................2211
  102.  
  103. 1122.. MMiisscceellllaanneeoouuss NNootteess......................................................................2233
  104.  
  105. 1133.. EExxttrraa CCoommppiilleerr WWaarrnniinnggss..............................................................2244
  106.     Alignment Problems....................................24
  107.  
  108. 1144.. TThhee LLIINNTT CCoommmmaanndd LLiinnee..................................................................2266
  109.     Abbreviating Options:.................................30
  110.     Other Ways to Use LINT................................30
  111.     Summary Files.........................................30
  112.     LINT Libraries........................................31
  113.     Review of Inputs and Outputs..........................32
  114.     Multiple Definitions..................................32
  115.     Configuration Files...................................33
  116.  
  117.  
  118.  
  119.  
  120.  
  121. November, 1995                                        Page i
  122.  
  123.  
  124.  
  125. LINT Reference Manual                          Thinkage Ltd.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.                          CChhaapptteerr 11
  133.                         IInnttrroodduuccttiioonn
  134.  
  135.     LINT is  a program that examines C source code and makes
  136. note of  "irregularities" in  the code.  When LINT was first
  137. implemented, its  primary function  was  locating  bugs  and
  138. inefficiencies.   However, as  the  C  programming  language
  139. spread to  a variety  of  machines  and  systems,  LINT  was
  140. enhanced to  locate deviations from the strict definition of
  141. C.
  142.  
  143.     The ANSI  standard for  C now  provides  the  "official"
  144. definition of  C.   However,  the  ANSI  standard  does  not
  145. entirely describe the behavior of C implementations, because
  146. the standard  allows certain operations to be performed in a
  147. system-dependent  way.     If   a  program   is  written  in
  148. conformance with  the ANSI  standard, avoiding  such system-
  149. dependent features,  we say  that the  program is written in
  150. _S_t_r_i_c_t_ _C.
  151.  
  152.     Ideally, all  programs should  be written  in Strict  C,
  153. since these  programs are  maximally portable.   One  of the
  154. major functions  of LINT  is to detect code constructs which
  155. do not  conform with  Strict C.   Such  constructs are often
  156. valid and  can be used in working programs, but they are not
  157. truly portable  and may  be indications of loose programming
  158. style.  LINT shows where you have written non-portable code;
  159. for portability, you should try to remove such code.
  160.  
  161.     Before we  begin, we  should note  that it is inevitable
  162. that LINT  will miss  some problems  and will  also complain
  163. about code  that turns  out to be valid.  The designers have
  164. tried to  chart a course between too much laxness (which may
  165. miss significant  irregularities) and  too much  nit-picking
  166. (which produces  quantities of  irrelevant output  that  you
  167. will likely  ignore).  Thus we have designed this version of
  168. LINT to  report situations that are _u_s_u_a_l_l_y signs of errors.
  169. While odd  constructions and  unusual programming  style can
  170. confuse LINT  from time  to time,  the majority  of material
  171. that LINT locates should deserve the programmer's attention.
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. Page 2                                        November, 1995
  184.  
  185.  
  186.  
  187. Thinkage Ltd.                          LINT Reference Manual
  188.  
  189.  
  190.  
  191.                          CChhaapptteerr 22
  192.                       LLIINNTT DDiirreeccttiivveess
  193.  
  194.     LINT  understands   all  the   usual   C   preprocessing
  195. directives (e.g.  ##iinncclluuddee,, ##ddeeffiinnee,,  etc.).   In  addition,
  196. LINT recognizes  a number  of other directives that have the
  197. same sort of format:
  198.  
  199.           #pragma aligned
  200.           #pragma argsused
  201.           #pragma notreached
  202.           #pragma optresult
  203.           #pragma used
  204.           #pragma varargs
  205.  
  206. These directives  tell LINT  about special  features of your
  207. source code  and  allow  LINT  to  provide  more  meaningful
  208. diagnostic messages.   The  usage of  each LINT directive is
  209. explained later in the manual.
  210.  
  211.     ANSI C  compilers should  not reject  these special LINT
  212. directives; the  ANSI standard  says that  C  compilers  are
  213. supposed to  ignore  any  ##pprraaggmmaa  directives  they  do  not
  214. understand.     However,  non-ANSI  C  compilers  may  issue
  215. diagnostic messages  for these  ##pprraaggmmaa directives, and even
  216. some ANSI  C compilers may issue warnings about unrecognized
  217. ##pprraaggmmaas.
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. November, 1995                                        Page 3
  246.  
  247.  
  248.  
  249. LINT Reference Manual                          Thinkage Ltd.
  250.  
  251.  
  252.  
  253.                          CChhaapptteerr 33
  254.                         LLIINNTT OOuuttppuutt
  255.  
  256.     LINT generally  produces quite  a lot  of  output.    By
  257. default the output is written to the terminal, but it can be
  258. redirected to  a file  using the standard output redirection
  259. constructions on the LINT command line.
  260.  
  261.     The first  lines of  output  from  LINT  are  diagnostic
  262. messages comparable  to those  that might be produced by a C
  263. compiler.  These diagnostics describe easily detected things
  264. like syntax errors.
  265.  
  266.     Following this  comes output  that is  unique  to  LINT.
  267. Most lines in the output have the form
  268.  
  269.           filename,lineno: class: text
  270.  
  271. where filename  is the  name of one of the source files that
  272. LINT is  scanning and  lineno is  a line  number within that
  273. file.   The class field tells the type of problem found; see
  274. "Message Classes" below for more information.  The text part
  275. of the  message  provides  specific  information  about  the
  276. problem.
  277.  
  278.     Some lines may have the form
  279.  
  280.           libname: class: text
  281.  
  282. where libname  is the  name of  a LINT  Library.   For  more
  283. information on  LINT libraries, see the last section of this
  284. manual.
  285.  
  286.  
  287. MMeessssaaggee CCllaasssseess
  288.  
  289.     Each message  produced by LINT is labelled with a string
  290. indicating what  kind of problem the message describes.  The
  291. following message classes are recognized:
  292.  
  293. Error:
  294.      Same as  error messages  produced by the compiler: code
  295.      so incorrect  that there is no way to generate any sort
  296.      of object code.
  297.  
  298. Warning:
  299.      Marks a  construct that is invalid but a compiler could
  300.      still generate  some kind of object code.  For example,
  301.      the ANSI  standard does  not allow  assignments between
  302.      pointers of  different types,  but most  compilers  can
  303.  
  304.  
  305.  
  306.  
  307. Page 4                                        November, 1995
  308.  
  309.  
  310.  
  311. Thinkage Ltd.                          LINT Reference Manual
  312.  
  313.  
  314.  
  315.      still  generate   sensible  object  code  for  such  an
  316.      operation.
  317.  
  318. Unusual:
  319.      Marks a  construct which  is valid,  but which  is  not
  320.      often seen in C programs.  For example,
  321.  
  322.         i=i;
  323.  
  324.      is  valid  but  suspicious,  possibly  indicating  some
  325.      problem in your code.
  326.  
  327. Note:
  328.      Marks a  construct which  is invalid  but always  works
  329.      properly on the current machine.  For example,
  330.  
  331.         printf("%ld",1);
  332.  
  333.      is invalid  since %ld requires a lloonngg argument but 1 is
  334.      just iinntt.   However,  this  always  works  properly  on
  335.      machines where lloonngg and iinntt are the same size.
  336.  
  337. MachDepd:
  338.      Marks a  valid construct  whose  behavior  is  machine-
  339.      dependent.   For  example,  the  result  of  (-7/2)  is
  340.      machine-dependent, since  the ANSI standard allows this
  341.      kind of  division to  truncate either  towards or  away
  342.      from zero.
  343.  
  344. Extension:
  345.      Marks a  construct that  is an  extension to  the  ANSI
  346.      standard.
  347.  
  348. Efficiency:
  349.      Marks code  that has  been written  in  a  particularly
  350.      inefficient way, or using constructs that are likely to
  351.      execute slowly.
  352.  
  353. NotMinimal:
  354.      Marks a  construct which is valid ANSI C but may not be
  355.      accepted by older C compilers (e.g. vvooiidd ** pointers).
  356.  
  357. Info:
  358.      Provides cross-reference information while using LINT.
  359.  
  360. IntrnErr:
  361.      An internal  error in LINT itself (for example, a table
  362.      overflow).
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369. November, 1995                                        Page 5
  370.  
  371.  
  372.  
  373. LINT Reference Manual                          Thinkage Ltd.
  374.  
  375.  
  376.  
  377.  
  378. OOuuttppuutt GGrroouuppiinngg
  379.  
  380.     LINT output is grouped according to the functions of the
  381. source code.
  382.  
  383.     The first  line of a group of messages gives the name of
  384. a function or an external variable.  After that come all the
  385. messages pertaining  to that  function  or  variable.    The
  386. messages end  with a  blank line,  followed by  the group of
  387. messages for the next function or variable.
  388.  
  389.     Groups are sorted in alphabetical order according to the
  390. name of the function or variable.
  391.  
  392.     The first line of every function group gives the name of
  393. the function  and  the  type  of  value  that  the  function
  394. returns.   If LINT  has found a definition for the function,
  395. the first line of the function group is
  396.  
  397.           Function "NAME" returns "TYPE".
  398.  
  399. where NAME  is the name of the function and TYPE is the type
  400. of value that the function returns.
  401.  
  402.     If LINT  can't find  a definition for the function, LINT
  403. looks at the first _r_e_f_e_r_e_n_c_e to the function that appears in
  404. the source code and prints
  405.  
  406.           Function "NAME" is assumed to return "TYPE".
  407.  
  408. where TYPE  is the  type suggested  by the  way in which the
  409. function is  used.   In keeping  with the  rules of  C, LINT
  410. assumes that  a function  returns iinntt if the function is not
  411. explicitly declared  to have a different type.  If the first
  412. reference to  the function  does not use a return value from
  413. the function, the message is
  414.  
  415.           Function "NAME" assumed to return no value.
  416.  
  417.     If LINT scans a function definition and finds that there
  418. are no  rreettuurrnn statements  that return a value, LINT outputs
  419. the message
  420.  
  421.           Function "NAME" returns no value.
  422.  
  423. You should distinguish between this message and
  424.  
  425.           Function "NAME" returns void.
  426.  
  427.  
  428.  
  429.  
  430.  
  431. Page 6                                        November, 1995
  432.  
  433.  
  434.  
  435. Thinkage Ltd.                          LINT Reference Manual
  436.  
  437.  
  438.  
  439. The vvooiidd  message appears  when  a  function  is  explicitly
  440. declared with  the vvooiidd  keyword.   The "no  value"  message
  441. appears when a function definition has no rreettuurrnn statements.
  442.  
  443.     The first  appearance of an external variable is treated
  444. in much  the same way as the first appearance of a function.
  445. You will see a message like
  446.  
  447.           External "NAME" is "TYPE".
  448.  
  449. or
  450.  
  451.           External "NAME" is assumed to be "TYPE".
  452.  
  453.     With one  exception, the  messages we  have described so
  454. far are always issued, whether or not there are errors.  The
  455. exception is  when  a  symbol  appears  in  a  LINT  library
  456. (described later  on) and is not referenced in normal source
  457. code.   Messages about  library functions and variables only
  458. appear if the symbol is used in source code.
  459.  
  460.     Other messages  in LINT  output describe situations that
  461. may be  errors.  These messages refer to difficulties within
  462. the function with which they are grouped.
  463.  
  464.  
  465. TTyyppee IInnffoorrmmaattiioonn
  466.  
  467.     At the  end of  its output,  LINT displays  a  block  of
  468. information describing  the types of the program.  A typical
  469. line of output is
  470.  
  471.           filename,lineno: type
  472.  
  473. where filename  is the  name of  the file where the type was
  474. defined and  lineno is  the line number where the definition
  475. began.
  476.  
  477.     LINT provides information about any ttyyppeeddeeffs, enumerated
  478. types, structures,  and/or unions  that were involved in the
  479. messages produced.   This lets you locate the definitions of
  480. these types.
  481.  
  482.     If a  type appears  twice in this list, it usually means
  483. that there is more than one definition for the same type and
  484. the types are not assignment-compatible.
  485.  
  486.     LINT also  checks for  structures and  unions which  are
  487. used in  functions and which have been incompletely defined.
  488. Incomplete definitions  are acceptable as long as there is a
  489. complete definition  somewhere.   All  complete  definitions
  490.  
  491.  
  492.  
  493. November, 1995                                        Page 7
  494.  
  495.  
  496.  
  497. LINT Reference Manual                          Thinkage Ltd.
  498.  
  499.  
  500.  
  501. have to be identical.  If complete definitions conflict with
  502. each other, LINT issues a diagnostic beginning with
  503.  
  504.           filename : type
  505.  
  506. where filename is the name of a file where the type was used
  507. and found to conflict with another definition.
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555. Page 8                                        November, 1995
  556.  
  557.  
  558.  
  559. Thinkage Ltd.                          LINT Reference Manual
  560.  
  561.  
  562.  
  563.                          CChhaapptteerr 44
  564.                       LLIINNTT CCoonnvveennttiioonnss
  565.  
  566.     A function  is  _d_e_f_i_n_e_d  by  the  function  header  that
  567. actually starts  the function.  This tells the type of value
  568. that the function returns and describes the arguments of the
  569. function.   An external variable is _d_e_f_i_n_e_d by a declaration
  570. for the  variable that is outside the scope of all functions
  571. and that does not include the keyword eexxtteerrnn.
  572.  
  573.     A function is _d_e_c_l_a_r_e_d by a declaration or function call
  574. inside another  function.   An external variable is _d_e_c_l_a_r_e_d
  575. by a  declaration that  includes the keyword eexxtteerrnn.  Such a
  576. variable  declaration   does  not  allocate  space  for  the
  577. variable; it  merely describes  the type of the variable and
  578. presumes that the variable is defined elsewhere.
  579.  
  580.     A variable  is _s_e_t  if it  is assigned  a value  or if a
  581. pointer to  the variable is taken.  Similarly, a variable is
  582. _u_s_e_d if  its value  is used  or if a pointer is taken.  (You
  583. might wonder  why taking  a pointer marks a variable as both
  584. "set" and  "used".   The answer  is that once a pointer to a
  585. variable is  taken, LINT  can't keep track of assignments or
  586. uses of  the variable through the pointer.  Once the pointer
  587. is taken, LINT can only assume that the data object may have
  588. been both set and used.)
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617. November, 1995                                        Page 9
  618.  
  619.  
  620.  
  621. LINT Reference Manual                          Thinkage Ltd.
  622.  
  623.  
  624.  
  625.                          CChhaapptteerr 55
  626.             UUnnuusseedd DDeeffiinniittiioonnss aanndd DDeeccllaarraattiioonnss
  627.  
  628.     One of  the easiest  problems for  LINT  to  find  is  a
  629. variable or  function that is defined but not used or called
  630. in the  rest of  the program.   Such  items can  usually  be
  631. deleted, since  they are  not performing any function in the
  632. program.   The diagnostic  messages for  such situations are
  633. listed and explained below.
  634.  
  635. Function "NAME" is never called.
  636.      The given  function was  defined in the source code but
  637.      never called.
  638.  
  639. External "NAME" is never used.
  640.      The given external variable was defined but never used.
  641.  
  642. External "NAME" is defined but never set or used.
  643.      This is essentially the same as the previous message.
  644.  
  645. External "NAME" is set but never used.
  646.      The given  external variable  was assigned a value, but
  647.      then was never used for anything.
  648.  
  649. Messages are  _n_o_t generated if a symbol in a LINT library is
  650. unused.
  651.  
  652.  
  653. MMaarrkkiinngg SSyymmbboollss AAss UUsseedd
  654.  
  655.     Sometimes, you  may  intentionally  declare  a  variable
  656. without using  it.   For example, suppose a variable is only
  657. used inside  a ##iiff  block and  that block  of  code  is  not
  658. compiled because  the ##iiff  condition is not met.  LINT would
  659. normally issue  an error message for this condition, but you
  660. might not consider this situation an error.
  661.  
  662.     To avoid  this sort  of message,  you can  add the  LINT
  663. directive
  664.  
  665.           #pragma used NAME NAME NAME ...
  666.  
  667. to your  source code.  This tells LINT that the names listed
  668. in the  directive are  used by  your  program,  even  if  it
  669. doesn't look like they are.
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679. Page 10                                       November, 1995
  680.  
  681.  
  682.  
  683. Thinkage Ltd.                          LINT Reference Manual
  684.  
  685.  
  686.  
  687.                          CChhaapptteerr 66
  688.             UUnnddeeffiinneedd oorr UUnnddeeccllaarreedd DDaattaa OObbjjeeccttss
  689.  
  690.     LINT uses  a simple-minded  way  to  find  places  where
  691. undefined variables  are used:  a variable  is assumed to be
  692. undefined if  a statement  using the variable appears in the
  693. code before  the variable is set.  Of course, it is possible
  694. to construct  programs where  this approach fails.  With the
  695. use of  spaghetti-like ggoottoos,  the top-down technique can be
  696. outwitted.
  697.  
  698.     Because static  and external variables are automatically
  699. initialized  to  zero  by  the  compiler  if  they  are  not
  700. initialized explicitly,  LINT does not pick up problems with
  701. these variables.
  702.  
  703.     The following  diagnostics pertain  to data objects that
  704. are used before they are set, defined, or declared.
  705.  
  706. Function "NAME" is called but never defined.
  707.      The source  code contains a call to the given function,
  708.      but the function is not defined anywhere in the code.
  709.  
  710. "NAME" is set but never defined.
  711.      The given  variable has  been assigned  a value,  but a
  712.      proper definition does not appear in the source code.
  713.  
  714. "NAME" is used but never defined.
  715.      The value  of the  given variable  was  used,  but  the
  716.      variable was never defined.
  717.  
  718. "NAME" is used but never defined or set.
  719.      The value  of the given variable has been used, but the
  720.      variable was neither defined nor set.
  721.  
  722. "NAME" is defined and used but never set.
  723.      The given  variable is defined and used, but never set.
  724.      This message  is only issued for local variables, since
  725.      all external variables are automatically initialized to
  726.      zero (if no explicit initialization is specified).
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741. November, 1995                                       Page 11
  742.  
  743.  
  744.  
  745. LINT Reference Manual                          Thinkage Ltd.
  746.  
  747.  
  748.  
  749.                          CChhaapptteerr 77
  750.                       UUnnrreeaacchhaabbllee CCooddee
  751.  
  752.     LINT attempts  to detect  parts of  the source code that
  753. cannot  be   reached  (for  example,  unlabelled  statements
  754. following a  ggoottoo).  It also attempts to find loops that can
  755. never be exited from the bottom, such as wwhhiillee((11))......  At the
  756. same time,  LINT finds loops that cannot be entered from the
  757. top.
  758.  
  759.     The message that is issued for detected unreachable code
  760. is
  761.  
  762.           Non reachable code at "TEXT".
  763.  
  764. where TEXT is the source code that cannot be reached.
  765.  
  766.  
  767. MMaarrkkiinngg UUnnrreeaacchhaabbllee CCooddee
  768.  
  769.     LINT cannot  detect functions which are called and never
  770. return (for  example,  ones  that  terminate  execution  via
  771. exit).  This means that it is possible for LINT to miss some
  772. unreachable code, as in
  773.  
  774.           g()
  775.           {
  776.               exit(-1);
  777.           }
  778.           f()
  779.           {
  780.               ...
  781.               g();
  782.               /* everything that follows
  783.                * is unreachable */
  784.               ...
  785.           }
  786.  
  787.     To mark  this kind  of situation,  you can  use the LINT
  788. directive
  789.  
  790.           #pragma notreached
  791.  
  792. When this  directive  appears  in  your  source  code,  LINT
  793. regards  any   source  code   following  the   directive  as
  794. unreachable, up  to  the  end  of  the  block  or  the  next
  795. statement label.   Appropriate  diagnostic messages  will be
  796. issued.
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803. Page 12                                       November, 1995
  804.  
  805.  
  806.  
  807. Thinkage Ltd.                          LINT Reference Manual
  808.  
  809.  
  810.  
  811.                          CChhaapptteerr 88
  812.                    FFuunnccttiioonn RReettuurrnn VVaalluueess
  813.  
  814.     LINT reports functions that contain both
  815.  
  816.           return( expression );
  817.  
  818. and
  819.  
  820.           return;
  821.  
  822. This kind  of situation usually results in errors (since the
  823. calling function  may assume  a value  is being returned but
  824. one of the rreettuurrnn statements does not return a value).
  825.  
  826.     Correspondingly, LINT  makes note  of whether  or not  a
  827. call to  a function  makes use  of a  return value  from the
  828. function.   If the  caller expects  a value but the function
  829. does not  return one,  it is clearly a bug.  If the function
  830. returns a value but the the caller does not use it, it could
  831. be an error, an inefficiency, or sloppy programming style.
  832.  
  833.     If a  function definition  contains no rreettuurrnn statements
  834. that return  a value,  LINT regards the function type as iinntt
  835. unless it is explicitly declared differently.  If LINT finds
  836. a reference  to the  function before  it finds  the function
  837. definition, it  assumes that  the function  returns a  value
  838. unless  the   function  is   explicitly  declared  as  vvooiidd.
  839. Programmers who  are used  to looser controls than this will
  840. find themselves with a large number of diagnostic messages.
  841.  
  842.     The messages  related  to  function  return  values  are
  843. listed below.
  844.  
  845. Value is used but none returned.
  846.      A function  did not  return a  value, but the statement
  847.      that called  the function  behaved as  if a  value  was
  848.      returned.
  849.  
  850. Function NAME has no return value
  851.      A function  was  defined  as  returning  a  value  (the
  852.      function is not vvooiidd)) but it did not contain a
  853.  
  854.         return(expression)
  855.  
  856.      statement.
  857.  
  858. Return value ignored.
  859.      The given function contains a
  860.  
  861.  
  862.  
  863.  
  864.  
  865. November, 1995                                       Page 13
  866.  
  867.  
  868.  
  869. LINT Reference Manual                          Thinkage Ltd.
  870.  
  871.  
  872.  
  873.         return(expression);
  874.  
  875.      statement, but the caller never uses the return result.
  876.  
  877. Return value sometimes ignored.
  878.      This is  similar to the last situation, except that the
  879.      return result is sometimes used, sometimes not.
  880.  
  881.  
  882. IIggnnoorriinngg RReettuurrnn VVaalluueess
  883.  
  884.     There is always the possibility that you want to write a
  885. function whose  return value  can be ignored.  The C library
  886. has several  functions whose  return value  is  superfluous.
  887. For example,
  888.  
  889.           strcpy(A,B)
  890.  
  891. copies string  B into  string A  and returns a pointer to A.
  892. This is  unnecessary, since the caller already has a pointer
  893. to A.
  894.  
  895.     LINT lets you mark functions with optional return values
  896. by using  a directive  similar to  the ##directives  of the C
  897. preprocessor.
  898.  
  899.           #pragma optresult
  900.  
  901. can  be  placed  immediately  before  the  definition  of  a
  902. function  that  returns  an  optional  result.    LINT  then
  903. recognizes that  this function  returns a result that can be
  904. ignored; LINT  does not give error messages if the result is
  905. ignored.
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927. Page 14                                       November, 1995
  928.  
  929.  
  930.  
  931. Thinkage Ltd.                          LINT Reference Manual
  932.  
  933.  
  934.  
  935.                          CChhaapptteerr 99
  936.                        TTyyppee CChheecckkiinngg
  937.  
  938.     LINT enforces stronger type-checking than most compilers
  939. do.   In expressions  where  different  types  of  data  are
  940. intermixed,  LINT   observes  the   strict  conventions  for
  941. conversions of  data and  requires that  everything else  be
  942. properly cast.
  943.  
  944.     LINT checks for type incompatibilities in three places:
  945.  
  946.  (a) in the arguments passed to functions
  947.  (b) in the return values received by functions
  948.  (c) in structure manipulations
  949.  
  950. For fullest  type-checking, the  code should  use prototypes
  951. wherever possible.  LINT also checks for situations in which
  952. some function  calls take  place with  a prototype  in scope
  953. while others do not.
  954.  
  955.     When arguments  are passed  to functions,  LINT issues a
  956. diagnostic if the argument type passed by the caller differs
  957. from the  argument type  expected by  the  called  function.
  958. Similarly, LINT  complains if  the argument type returned by
  959. the called  function differs from the argument type expected
  960. by the  caller.  The messages associated with this situation
  961. are given below.
  962.  
  963. Argument N is "TYPE1", but declared as "TYPE2".
  964.      When the given function was called, the caller passed a
  965.      value of  type TYPE1  for argument  number N,  but  the
  966.      called  function  expected  a  value  of  TYPE2.    For
  967.      example, you might see
  968.  
  969.         Argument 2 is "int", declared "unsigned int".
  970.  
  971.      This indicates  that the caller passed an integer value
  972.      as the  second argument of the function, but the called
  973.      function expected an unsigned integer.
  974.  
  975. Argument N is "TYPE", but declared as a different "TYPE"
  976.      This is  an odd  situation where  the definition  and a
  977.      declaration give  the argument different types, but the
  978.      strings used to print out TYPE turn out to be the same.
  979.      For example, suppose that a function has a local ssttrruucctt
  980.      X, but  there is also an external ssttrruucctt X which is not
  981.      compatible  with   the  local  one.    If  the  program
  982.      invalidly tries to combine external and local variables
  983.      of type  X, you  get the above message; even though the
  984.      types have the same name, they are different.  The same
  985.  
  986.  
  987.  
  988.  
  989. November, 1995                                       Page 15
  990.  
  991.  
  992.  
  993. LINT Reference Manual                          Thinkage Ltd.
  994.  
  995.  
  996.  
  997.      sort of  situation may  happen with  other  LINT  error
  998.      messages.
  999.  
  1000. "NAME" is redeclared as function type "TYPE".
  1001.      When NAME  was first  declared, it was said to return a
  1002.      value of  one type.  Now NAME has been declared or used
  1003.      as a function returning a different type of value.
  1004.  
  1005. "NAME" declared as returning "TYPE"
  1006.      The function NAME has been declared as returning a TYPE
  1007.      that is different than its definition.
  1008.  
  1009. "NAME" declared as "TYPE"
  1010.      The variable NAME has been declared with a TYPE that is
  1011.      different than its definition.
  1012.  
  1013. "NAME" is redefined as function.
  1014.      NAME was  originally declared as a variable, but is now
  1015.      being defined as a function.
  1016.  
  1017.     LINT also  issues a  message whenever  a data  object is
  1018. implicitly shortened.  For example, suppose we have
  1019.  
  1020.           long l;
  1021.           int i;
  1022.             /* stuff */
  1023.           i = l;
  1024.  
  1025.     The C  compiler automatically  shortens the long "l" and
  1026. assigns the  result to  "i".   However, LINT flags this as a
  1027. potential  problem   (since  different   integer  sizes   on
  1028. different machines  may affect  how this  works).   No error
  1029. message is  issued if  the conversion is done explicitly, as
  1030. in
  1031.  
  1032.           i = (int) l;
  1033.  
  1034.     As a  final note  about type-checking, LINT occasionally
  1035. gets some  complicated types  wrong.   For example, warnings
  1036. about structures  that contain  arrays of  structures do not
  1037. give the  right type  (namely ssttrruucctt).    The  same  problem
  1038. occurs when  LINT is  not given  the internal structure of a
  1039. ssttrruucctt.   For example,  it is  valid for  a source module to
  1040. declare
  1041.  
  1042.           struct ABC *ptr;
  1043.  
  1044. without describing the internal structure of the ABC ssttrruucctt.
  1045. In such  cases, LINT  does not  have enough  information  to
  1046. determine if  code is valid, so the warning messages may not
  1047. be entirely accurate.
  1048.  
  1049.  
  1050.  
  1051. Page 16                                       November, 1995
  1052.  
  1053.  
  1054.  
  1055. Thinkage Ltd.                          LINT Reference Manual
  1056.  
  1057.  
  1058.  
  1059.                          CChhaapptteerr 1100
  1060.                    FFuunnccttiioonn DDeeccllaarraattiioonnss
  1061.  
  1062.     LINT compares  all the  available prototype declarations
  1063. for a  function to  make  sure  that  the  prototypes  match
  1064. _e_x_a_c_t_l_y.   For example,  LINT  notes  situations  where  one
  1065. prototype gives  vvooiidd **  as the  type of  an argument  while
  1066. another types  the same  argument as  cchhaarr **.   In practice,
  1067. there is  no difference  between these  two  pointer  types;
  1068. however, LINT  makes note of the situation because it may be
  1069. indicative of an error.
  1070.  
  1071.     In addition to checking that the argument types expected
  1072. by a  called function match the argument types passed by the
  1073. caller, LINT  also  checks  that  the  _n_u_m_b_e_r  of  arguments
  1074. expected by  the  called  function  matches  the  number  of
  1075. arguments passed  by the caller.  If there is a mismatch, it
  1076. prints
  1077.  
  1078.           Called with N arguments, requires M
  1079.  
  1080. where N  is the  number of  arguments that the caller passes
  1081. and M is the number of arguments that the function expects.
  1082.  
  1083.     Whenever possible,  LINT checks  to  see  that  argument
  1084. declarations in  function prototypes  agree exactly with the
  1085. declarations  in   the  function   definition.      If   the
  1086. declarations do not agree, LINT outputs
  1087.  
  1088.           Prototype argument N is "TYPE" but declared as
  1089.           "TYPE"
  1090.  
  1091. LINT expects  argument declarations  to match  exactly.  For
  1092. example, the vvooiidd ** type is considered assignment-compatible
  1093. with all pointer types and therefore there is not a conflict
  1094. between vvooiidd ** and another pointer type.  Nevertheless, LINT
  1095. points out  the difference,  simply to  warn you  that there
  1096. seems to be a discrepancy in your code.
  1097.  
  1098.     Finally, LINT makes sure that the number of arguments in
  1099. a prototype  declaration matches  the number in the function
  1100. definition.  If not, LINT prints
  1101.  
  1102.           Prototyped with N arguments, but requires M
  1103.  
  1104. where M and N are both integers.
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113. November, 1995                                       Page 17
  1114.  
  1115.  
  1116.  
  1117. LINT Reference Manual                          Thinkage Ltd.
  1118.  
  1119.  
  1120.  
  1121.  
  1122. TThhee ##pprraaggmmaa vvaarraarrggss DDiirreeccttiivvee
  1123.  
  1124.     In earlier  versions of  C it  was valid  to  pass  more
  1125. arguments than  the function definition specifies or to pass
  1126. fewer arguments.  This is not valid in ANSI C unless you use
  1127. the "..."  construct in  the prototype;  however, older code
  1128. may still  make use  of  such  calling  sequences  and  most
  1129. compilers still handle the situation properly.
  1130.  
  1131.     In  order  to  handle  all  the  possibilities  of  this
  1132. situation, LINT  introduces the  ##pprraaggmmaa vvaarraarrggss  directive.
  1133. The directive has two forms.
  1134.  
  1135.           #pragma varargs N
  1136.  
  1137. indicates that  the next  function to  be defined can take a
  1138. variable number  of arguments  but must  have a minimum of N
  1139. arguments.  For example, we might write
  1140.  
  1141.           #pragma varargs 3
  1142.           int Mini(N,a,b,c,d);
  1143.           int N,a,b,c,d;
  1144.           { ....
  1145.  
  1146. to declare  a function  Mini that  must take  at least three
  1147. arguments and  can have  more.   In this case, LINT does not
  1148. issue an  error message  if you  have at least three integer
  1149. arguments present.
  1150.  
  1151.     With this  form of  the ##pprraaggmmaa  vvaarraarrggss directive, LINT
  1152. typechecks all the arguments that are present.  In the above
  1153. example, LINT  ensures that  all the  arguments being passed
  1154. are integers.
  1155.  
  1156.     The second form of the directive is
  1157.  
  1158.           #pragma varargs N M
  1159.  
  1160. where both  N and  M are  integers.  This indicates that the
  1161. next function  to be  defined  must  have  a  minimum  of  N
  1162. arguments, and  LINT should  typecheck up  to M arguments if
  1163. they appear.   For  example, you  can imagine  a printf-like
  1164. function that  takes a format string plus one or more values
  1165. to print.  This could be preceded with
  1166.  
  1167.           #pragma varargs 2 1
  1168.  
  1169. showing that  the function must always have two arguments (a
  1170. format string  and at  least one output value) but that only
  1171.  
  1172.  
  1173.  
  1174.  
  1175. Page 18                                       November, 1995
  1176.  
  1177.  
  1178.  
  1179. Thinkage Ltd.                          LINT Reference Manual
  1180.  
  1181.  
  1182.  
  1183. the first  argument should  be typechecked (since the output
  1184. value(s) need not have a fixed type).
  1185.  
  1186.     The directive can also take the form
  1187.  
  1188.           #pragma varargs printf
  1189.           #pragma varargs scanf
  1190.  
  1191. These forms  may be  used to  indicate functions  that  take
  1192. format strings comparable to the strings of printf and scanf
  1193. (respectively).   LINT  compares  the  placeholders  in  the
  1194. format string  to the types of the arguments that follow the
  1195. format string, and reports any conflicts between types.  For
  1196. example, it  tells you if the argument corresponding to a %s
  1197. placeholder is an iinntt value (incompatible with %s).
  1198.  
  1199.  
  1200. TThhee ##pprraaggmmaa aarrggssuusseedd DDiirreeccttiivvee
  1201.  
  1202.     Some functions  are able  to use  all the arguments they
  1203. are passed  without actually  referring to every argument by
  1204. name.   For example,  consider a  function Max10  which  can
  1205. accept up  to 10  iinntt arguments  and return the value of the
  1206. largest argument.   The first argument passed to Max10 tells
  1207. how many  values have  actually been  passed.  This could be
  1208. defined with
  1209.  
  1210.           int Max10(N,a,b,c,d,e,f,g,h,i)
  1211.           int N,a,b,c,d,e,f,g,h,i;
  1212.           {
  1213.               int j,m,*p;
  1214.               m = a;
  1215.               p = &a;
  1216.               for (j=1; j < N; ++j)
  1217.                   if (p[j] > m) m = p[j];
  1218.               return(m);
  1219.           }
  1220.  
  1221. As  you  can  see,  the  function  does  not  refer  to  the
  1222. parameters b,  c, etc.  by name.   However,  it does look at
  1223. their values, since it walks through the stack using offsets
  1224. from a.  Therefore the values are used.
  1225.  
  1226.     This sort  of coding practice is a violation of the ANSI
  1227. standard.   The standard  doesn't let  you use subscripts to
  1228. access memory  locations outside  the  bounds  of  a  single
  1229. object, so  p[j] is  invalid if j is not zero.  On the other
  1230. hand, many  compilers still  accept code like this and older
  1231. programs may use it.
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237. November, 1995                                       Page 19
  1238.  
  1239.  
  1240.  
  1241. LINT Reference Manual                          Thinkage Ltd.
  1242.  
  1243.  
  1244.  
  1245.     For  such   programs,  you  can  avoid  some  diagnostic
  1246. messages from LINT by putting the LINT directive
  1247.  
  1248.           #pragma argsused
  1249.  
  1250. on a line preceding the function, as in
  1251.  
  1252.           #pragma argsused
  1253.           int Max10(N,a,b,c,d,e,f,g,h,i)
  1254.              ...
  1255.  
  1256. This tells  LINT that  the function  uses all its arguments,
  1257. even if it doesn't appear to.
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299. Page 20                                       November, 1995
  1300.  
  1301.  
  1302.  
  1303. Thinkage Ltd.                          LINT Reference Manual
  1304.  
  1305.  
  1306.  
  1307.                          CChhaapptteerr 1111
  1308.                       AAlltteerrnnaattee FFoorrmmss
  1309.  
  1310.     For compatibility  with the  Bell Labs' version of LINT,
  1311. this version  of LINT may accept some directives in the form
  1312. of  comments.     These   are   only   recognized   if   the
  1313. +ControlComments option  is specified  on the  LINT  command
  1314. line.
  1315.  
  1316.           /*VARARGSN*/
  1317.  
  1318. (where N is an integer) is automatically converted to
  1319.  
  1320.           #pragma varargs 0 N
  1321.  
  1322. For example,
  1323.  
  1324.           /*VARARGS3*/
  1325.  
  1326. is equivalent to
  1327.  
  1328.           #pragma varargs 0 3
  1329.  
  1330. In addition,
  1331.  
  1332.           /*VARARGS*/
  1333.  
  1334. (with no value N) is equivalent to
  1335.  
  1336.           #pragma varargs 0
  1337.  
  1338.     In addition to VARARGS, the comment
  1339.  
  1340.           /*ARGSUSED*/
  1341.  
  1342. is automatically converted to
  1343.  
  1344.           #pragma argsused
  1345.  
  1346. and the comment
  1347.  
  1348.           /*NOTREACHED*/
  1349.  
  1350. is equivalent to
  1351.  
  1352.           #pragma notreached
  1353.  
  1354.     In all  cases, the  comment form  may not  contain white
  1355. space  (blanks,   tabs,  or   new-lines).    All  alphabetic
  1356. characters must  be in  upper case  and there can be nothing
  1357.  
  1358.  
  1359.  
  1360.  
  1361. November, 1995                                       Page 21
  1362.  
  1363.  
  1364.  
  1365. LINT Reference Manual                          Thinkage Ltd.
  1366.  
  1367.  
  1368.  
  1369. else in  the comment  except the keyword and any number that
  1370. should follow.
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423. Page 22                                       November, 1995
  1424.  
  1425.  
  1426.  
  1427. Thinkage Ltd.                          LINT Reference Manual
  1428.  
  1429.  
  1430.  
  1431.                          CChhaapptteerr 1122
  1432.                     MMiisscceellllaanneeoouuss NNootteess
  1433.  
  1434.     LINT  always   uses  the  full  name  of  functions  and
  1435. variables, and  always distinguishes between upper and lower
  1436. case letters.  This is the way that C compilers are supposed
  1437. to work  as  well.    However,  some  compilers  or  loaders
  1438. truncate long  names to  a certain number of characters, and
  1439. some compilers  or loaders  do not  distinguish between  the
  1440. case of  letters in names.  For this reason, LINT issues the
  1441. following warnings.
  1442.  
  1443. NAME1 and NAME2 not unique in first N caseless characters.
  1444.      N is  the number  of characters  to which  names may be
  1445.      truncated to meet loader requirements.
  1446.  
  1447. NAME1 and NAME2 not unique without case distinction.
  1448.      This applies  to names  like VAR,  var, and Var used in
  1449.      the same program.
  1450.  
  1451.     LINT detects  redeclaration of  functions and  variables
  1452. defined outside  the scope  of any  function.   The  set  of
  1453. messages dedicated to this kind of problem are given below.
  1454.  
  1455. NAME redeclared.
  1456.      A given  variable has  been  invalidly  declared  in  a
  1457.      second place.
  1458.  
  1459. NAME retyped as "TYPE".
  1460.      A given  variable has  been used  as if  it had  a type
  1461.      different from its declared type.
  1462.  
  1463. NAME redeclared with type "TYPE".
  1464.      The given  variable appears in a new declaration with a
  1465.      different type than it previously had.
  1466.  
  1467. NAME is redefined as function.
  1468.      A  name  that  was  previously  given  to  an  external
  1469.      variable has now been given to a function.
  1470.  
  1471.     LINT assumes  that sshhoorrtt  integers have  a length  of 16
  1472. bits and  that lloonngg  integers have  a  length  of  32  bits,
  1473. regardless of  what length  these data  types have  on  your
  1474. machine.   The reason  is that  short and  long integers are
  1475. guaranteed to  have at  least these lengths on all machines.
  1476. Your hardware  may allow  longer integers  (for example,  36
  1477. bits) but  code that uses the increased size is not portable
  1478. to machines  with smaller  words.  For the same reason, LINT
  1479. assumes that  all characters  are 8-bit  signed  quantities,
  1480. even though they may be longer or unsigned on your machine.
  1481.  
  1482.  
  1483.  
  1484.  
  1485. November, 1995                                       Page 23
  1486.  
  1487.  
  1488.  
  1489. LINT Reference Manual                          Thinkage Ltd.
  1490.  
  1491.  
  1492.  
  1493.                          CChhaapptteerr 1133
  1494.                   EExxttrraa CCoommppiilleerr WWaarrnniinnggss
  1495.  
  1496.     In addition  to the  diagnostics produced especially for
  1497. LINT, the  LINT output  also  contains  all  the  error  and
  1498. warning messages  produced by  the parsing  phase of  the  C
  1499. compiler.  Most of these are self-explanatory, but there are
  1500. a few that deserve further comment.
  1501.  
  1502. Constant "CONSTANT" too large for "TYPE".
  1503.      As noted  earlier, LINT  assumes short  integers are 16
  1504.      bits  long   and  long   integers  are  32  bits  long.
  1505.      Therefore you may get this message, even though a short
  1506.      or long  integer type  on your machine is actually long
  1507.      enough to hold a given constant.
  1508.  
  1509. Character constant with no characters.
  1510.      Some compilers do not accept a null character constant.
  1511.      Your compiler may accept such constants, but LINT still
  1512.      complains about the construct.
  1513.  
  1514. Constant valued logical expression.
  1515.      This refers to situations like
  1516.  
  1517.         while (1) { ... }
  1518.  
  1519.  
  1520. AAlliiggnnmmeenntt PPrroobblleemmss
  1521.  
  1522.     In addition  to the error messages listed above, you may
  1523. receive the warning
  1524.  
  1525.           Possible alignment problems with cast
  1526.  
  1527.     When casting  data of  one  type  to  data  of  another,
  1528. alignment problems  may occur.   For  example, there  may be
  1529. difficulties in  casting a  character pointer  to an integer
  1530. pointer if  the character  pointer is  not aimed  at a  word
  1531. boundary.   At times,  however, you  may have taken pains to
  1532. make sure  that this  kind of  alignment  problem  will  not
  1533. occur.   In particular, you may have created a function that
  1534. returns a  value or pointer that is suitably aligned for any
  1535. use.   This is true of functions like malloc; the value that
  1536. malloc returns  is officially  a vvooiidd  ** pointer,  but it is
  1537. suitably aligned to store any sort of data.
  1538.  
  1539.     If you  have a  function that returns a suitably aligned
  1540. pointer, you can tell LINT by placing
  1541.  
  1542.           #pragma aligned
  1543.  
  1544.  
  1545.  
  1546.  
  1547. Page 24                                       November, 1995
  1548.  
  1549.  
  1550.  
  1551. Thinkage Ltd.                          LINT Reference Manual
  1552.  
  1553.  
  1554.  
  1555. in front  of the  start of  the function  declaration.  This
  1556. tells LINT that the function itself deals with any alignment
  1557. problems.
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609. November, 1995                                       Page 25
  1610.  
  1611.  
  1612.  
  1613. LINT Reference Manual                          Thinkage Ltd.
  1614.  
  1615.  
  1616.  
  1617.                          CChhaapptteerr 1144
  1618.                    TThhee LLIINNTT CCoommmmaanndd LLiinnee
  1619.  
  1620. _S_y_n_t_a_x_:
  1621.           tlint [file] [option]*
  1622.  
  1623.           (+|-)ControlComments (-)  (+|-)Declarations (-)
  1624.           (+|-)Keep (-)             (+|-)StandardLibrary (+)
  1625.           (+|-)Verbose (-)          (+|-)Wide (-)
  1626.           Configuration=file        CrossReference=keyword
  1627.           Define=name=value         Include=directory
  1628.           INSTallation=file         Library=lib
  1629.           libraryName=string        Output=file
  1630.           Output+=file              StandardInclude=directory
  1631.           StandardLibrary=name      Summary=file
  1632.           Target=keyword            indeX=file
  1633.  
  1634. _E_x_a_m_p_l_e_s_:
  1635.           tlint myfile
  1636.           tlint x=files o=incls ln=proj def=PROJECT=1
  1637.  
  1638. _O_p_t_i_o_n_s_:
  1639. file
  1640.      is a  source file containing C code.  The other options
  1641.      on the  command line  determine whether LINT scans this
  1642.      file for  problem spots,  or uses  the file to create a
  1643.      summary or an entry in a LINT library.
  1644.  
  1645. indeX=file
  1646.      gives the  name of a text file.  Each line in this text
  1647.      file should  contain the  name of  one C  source  file.
  1648.      LINT checks  each of  these source  files individually.
  1649.      In addition  to a  source file name, a line in an index
  1650.      file  may   specify  ControlComments,   Configuration=,
  1651.      Include= and Define= options.  These options only apply
  1652.      to the  source file  named  on  the  same  line.    For
  1653.      example, if the line
  1654.  
  1655.         myfile define=VERSION=1
  1656.  
  1657.      appeared in  an index  file, LINT  would use  the given
  1658.      option when  examining myfile  but not  for other files
  1659.      named in  the index  file.   When processing  an  index
  1660.      line, LINT  normally uses  all the options appearing on
  1661.      the  main   command  line,   followed  by  the  options
  1662.      specified on  the index  line.    As  a  special  case,
  1663.      however, Include=  options on  a line  in an index file
  1664.      are used  before  any  Include=  options  on  the  LINT
  1665.      command line.  Only one indeX= option may appear on the
  1666.      command line.
  1667.  
  1668.  
  1669.  
  1670.  
  1671. Page 26                                       November, 1995
  1672.  
  1673.  
  1674.  
  1675. Thinkage Ltd.                          LINT Reference Manual
  1676.  
  1677.  
  1678.  
  1679. Configuration=file
  1680.      specifies a  configuration file  for LINT.    For  more
  1681.      information on configuration files, see below.
  1682.  
  1683. +ControlComments
  1684.      indicates that control comments of the type
  1685.  
  1686.         /*VARARGS*/
  1687.  
  1688.      should be  processed.  The default is -ControlComments,
  1689.      in  which   case  such   comments  are   ignored.     A
  1690.      ControlComments option  on a  line  in  an  index  file
  1691.      overrides any  ControlComments option  on the main LINT
  1692.      command line.
  1693.  
  1694. CrossReference=keyword
  1695.      indicates that  LINT output  should  include  a  cross-
  1696.      reference table  that shows  where symbols are defined,
  1697.      referenced,  set,   and  used.   (By  default,   cross-
  1698.      references are  not provided.)  Possible values for the
  1699.      keyword are:
  1700.  
  1701.      All - cross-references all symbols;
  1702.  
  1703.      External - only cross-references external symbols.
  1704.  
  1705. +Declarations
  1706.      may be  used when  creating a  LINT library  or summary
  1707.      file.   With this  option, LINT treats every file scope
  1708.      declaration  as   if  it  were  a  definition  for  the
  1709.      variable, instead of a simple reference.
  1710.  
  1711. Define=name=value
  1712.      has the same effect as
  1713.  
  1714.         #define name value
  1715.  
  1716.      in the C source code.  The option indicates that "name"
  1717.      should be  replaced with  "value" (as text) wherever it
  1718.      appears in  the source code being examined.  If "value"
  1719.      contains  blanks   or  tab  characters,  it  should  be
  1720.      enclosed in double or single quotes.
  1721.  
  1722. Include=directory
  1723.      is the  same as the Include= option for the C compiler.
  1724.      When LINT tries to find quoted include files, as in
  1725.  
  1726.         #include "file"
  1727.  
  1728.      it begins  by searching  the given  directory  for  the
  1729.      file.   If the  file is  not found there, LINT searches
  1730.  
  1731.  
  1732.  
  1733. November, 1995                                       Page 27
  1734.  
  1735.  
  1736.  
  1737. LINT Reference Manual                          Thinkage Ltd.
  1738.  
  1739.  
  1740.  
  1741.      any directory  named in  StandardInclude= options,  and
  1742.      finally searches the directory that contains the source
  1743.      file being  examined.   Any number  of Include= options
  1744.      may be  specified.   Directories are  searched  in  the
  1745.      order given on the command line.
  1746.  
  1747. INSTallation=file
  1748.      tells LINT  where to  find the  installation file.  The
  1749.      installation  file   tells   where   various   software
  1750.      components have  been installed.  For more information,
  1751.      see the section on _I_n_s_t_a_l_l_a_t_i_o_n_ _F_i_l_e_s below.
  1752.  
  1753.      If you  do not  specify an  INSTallation= option on the
  1754.      command line,  LINT checks  for an environment variable
  1755.      named LINT_INST  and uses  its value as the name of the
  1756.      installation file.   If  this environment variable does
  1757.      not exist, LINT uses the default installation file.
  1758.  
  1759. +Keep
  1760.      does  not   delete  intermediate   files  left  by  the
  1761.      preprocessor and the LINT steps.
  1762.  
  1763. Library=lib
  1764.      names a  LINT library that should be used when checking
  1765.      source code.  Any number of Library= options may appear
  1766.      on the  command line.   By  default, LINT automatically
  1767.      includes LINT  libraries of  standard C functions (e.g.
  1768.      printf) so that such functions are always recognized.
  1769.  
  1770. libraryName=string
  1771.      is used  when creating  a LINT  library.  See below for
  1772.      more details.
  1773.  
  1774. Output=file
  1775.      is used  when creating  a LINT  library or summary file
  1776.      (see below).   The output overwrites the file's current
  1777.      contents.
  1778.  
  1779. Output+=file
  1780.      is the  same as  Output=file,  except  that  output  is
  1781.      written to  the end  of the  current  contents  of  the
  1782.      specified file,  rather than  overwriting what the file
  1783.      already holds.
  1784.  
  1785. StandardInclude=directory
  1786.      is the  same as  the StandardInclude=  option for the C
  1787.      compiler.   When LINT tries to find include files whose
  1788.      names are enclosed in angle brackets, as in
  1789.  
  1790.         #include <file>
  1791.  
  1792.  
  1793.  
  1794.  
  1795. Page 28                                       November, 1995
  1796.  
  1797.  
  1798.  
  1799. Thinkage Ltd.                          LINT Reference Manual
  1800.  
  1801.  
  1802.  
  1803.      it begins  by searching  the given  directory  for  the
  1804.      file.   If the  file is  not found there, LINT searches
  1805.      directories named  in  Include=  options,  and  finally
  1806.      searches the  directory that  contains the  source file
  1807.      being examined.  Any number of StandardInclude= options
  1808.      may be  specified.   Directories are  searched  in  the
  1809.      order given on the command line.
  1810.  
  1811. StandardLibrary=name
  1812.      asks LINT  to include the standard library indicated by
  1813.      "name". The following names are recognized:
  1814.  
  1815.      C  -   the  standard   C  library.   This  is  included
  1816.      automatically, unless -StandardLibrary is specified.
  1817.  
  1818. -StandardLibrary
  1819.      does not include the standard C library routines.
  1820.  
  1821. Summary=file
  1822.      states that  the given  file is  a  summary  file  that
  1823.      should be  used as  input to  the LINT  operation.  See
  1824.      below for more on summary files.
  1825.  
  1826. Target=keyword
  1827.      controls the  kind of  problem-checking you want to do.
  1828.      The following keywords are recognized.
  1829.  
  1830.      Host -  describes any  problems that  may arise  if the
  1831.      program is  run on  the host  machine (i.e. the machine
  1832.      where you are running LINT).  This is the default.
  1833.  
  1834.      Extensions -  points out any extensions to C that might
  1835.      have been  used, as well as any machine-dependencies in
  1836.      the code.  It also describes the problems detected with
  1837.      Target=Host.
  1838.  
  1839.      Minimal -  points  out  any  features  that  may  cause
  1840.      problems  if  you  port  this  program  to  a  non-ANSI
  1841.      compiler.   This will  make note  of all  ANSI features
  1842.      used.   It also  describes the  problems detected  with
  1843.      Target=Extensions.
  1844.  
  1845. +Verbose
  1846.      prints out  the name  of the  file being examined.  The
  1847.      default is -Verbose.
  1848.  
  1849. +Wide
  1850.      prints output  in a  format that  is 132  columns wide.
  1851.      The default  is -Wide,  which prints  in  an  80-column
  1852.      format.
  1853.  
  1854.  
  1855.  
  1856.  
  1857. November, 1995                                       Page 29
  1858.  
  1859.  
  1860.  
  1861. LINT Reference Manual                          Thinkage Ltd.
  1862.  
  1863.  
  1864.  
  1865.  
  1866. _A_b_b_r_e_v_i_a_t_i_n_g_ _O_p_t_i_o_n_s_:
  1867.  
  1868.     The option  keywords given  above can  be abbreviated by
  1869. omitting any or all of the letters shown in lower case.  For
  1870. example, CrossReference=All may be abbreviated to
  1871.  
  1872.           crossref=all
  1873.           cref=all
  1874.           cr=all
  1875.           cr=a
  1876.  
  1877. and so  on.   When entering  option keywords,  you may  type
  1878. letters in upper, lower, or mixed case; the use of upper and
  1879. lower case  in this  documentation is  simply to  show  what
  1880. letters are and aren't required.
  1881.  
  1882.  
  1883. _O_t_h_e_r_ _W_a_y_s_ _t_o_ _U_s_e_ _L_I_N_T
  1884.  
  1885.     In addition  to checking C code for irregularities, LINT
  1886. can:
  1887.  
  1888. (a)  Extract a  summary file of information that can be used
  1889.      in other LINT operations.
  1890.  
  1891. (b)  Create a LINT library.
  1892.  
  1893. Summary files and LINT libraries are discussed below.
  1894.  
  1895.  
  1896. _S_u_m_m_a_r_y_ _F_i_l_e_s
  1897.  
  1898.     A summary file contains a "summary" of your source code:
  1899. the names  and types  of  all  the  external  variables  and
  1900. functions defined  or referenced in the code, plus any other
  1901. information LINT  may need  when checking  the code (such as
  1902. the declared  types of  function parameters).  Summary files
  1903. also record any error messages that might be issued by the C
  1904. compiler  when  parsing  the  source  code.    All  of  this
  1905. information is  stored in  a  special  format  that  is  not
  1906. directly readable by humans.
  1907.  
  1908.     To create a summary file from a normal source code file,
  1909. use the Output=file option, as in
  1910.  
  1911.           tlint src1.c output=summ
  1912.  
  1913. You can  add more  material to  the same  summary file using
  1914. Output+=file, as in
  1915.  
  1916.  
  1917.  
  1918.  
  1919. Page 30                                       November, 1995
  1920.  
  1921.  
  1922.  
  1923. Thinkage Ltd.                          LINT Reference Manual
  1924.  
  1925.  
  1926.  
  1927.           tlint src2.c output+=summ
  1928.  
  1929. This appends  new material  to the  existing contents of the
  1930. summary file.
  1931.  
  1932.     When LINT  creates a  Summary file, LINT only summarizes
  1933. your source  code and checks for syntax errors.  It does not
  1934. check for  such problems  as non-portable constructs or type
  1935. mismatches.   However, you  can run  a summary  file through
  1936. LINT again to do standard type-checking.  For example,
  1937.  
  1938.           tlint srcfile output=lf
  1939.           tlint summ=lf
  1940.  
  1941. creates a  summary file,  then uses  the information  in the
  1942. summary file  to see if types match in symbol references and
  1943. definitions.
  1944.  
  1945.     The reason for creating summary files is the same as the
  1946. reason for  breaking up the source code of your program into
  1947. several source  files: it is easier to deal with source code
  1948. in small pieces than in one big hunk.  Some users may keep a
  1949. summary file  for every  source file.   If  the code  in one
  1950. source file  is changed,  you can create a summary file from
  1951. that source  file, then  run all  the summary  files of  the
  1952. program through  LINT to  see if  the change  has caused any
  1953. problems.   This is  much faster  than using LINT on all the
  1954. raw source code.
  1955.  
  1956.  
  1957. _L_I_N_T_ _L_i_b_r_a_r_i_e_s
  1958.  
  1959.     A LINT  library is similar to a summary file, in that it
  1960. contains  a  summary  of  C  source  code.    However,  LINT
  1961. libraries are  intended to  parallel  the  way  that  object
  1962. libraries work.
  1963.  
  1964.     To create  a LINT  library,  specify  both  the  Output=
  1965. option and the libraryName= option on the LINT command line.
  1966. For example,
  1967.  
  1968.           tlint file output=mylib libname="abc"
  1969.  
  1970. creates a  LINT library  named abc  in the  file mylib. This
  1971. name is  used in LINT diagnostic messages related to symbols
  1972. found in  the LINT  library.   Using LINT  in this  way only
  1973. generates minimal  messages; full  messages are printed when
  1974. you actually use the LINT library.
  1975.  
  1976.     To use  a LINT  library, specify  the Library= option on
  1977. the LINT command line, as in
  1978.  
  1979.  
  1980.  
  1981. November, 1995                                       Page 31
  1982.  
  1983.  
  1984.  
  1985. LINT Reference Manual                          Thinkage Ltd.
  1986.  
  1987.  
  1988.  
  1989.  
  1990.           tlint myfile library=mylib
  1991.  
  1992. When LINT  finds that  myfile contains  a  reference  to  an
  1993. undefined symbol,  LINT checks  the information in the given
  1994. LINT library  to see  if the  symbol is defined there.  This
  1995. works just  like compiling  a module  while referring  to an
  1996. object library.   No  error occurs  if a  symbol in the LINT
  1997. library has  the same  name as  a symbol in the source file;
  1998. the source file symbol is the one that is used.
  1999.  
  2000.     Functions should  only be  placed in a LINT library when
  2001. you are sure they contain no errors.  LINT does not look for
  2002. errors when it is creating a LINT library.
  2003.  
  2004.  
  2005. _R_e_v_i_e_w_ _o_f_ _I_n_p_u_t_s_ _a_n_d_ _O_u_t_p_u_t_s
  2006.  
  2007.     To specify  a file  as an  input, simply give the file's
  2008. name.  To specify a summary file as input, use Summary=file.
  2009. To specify  a LINT library as input, use Library=file.  LINT
  2010. uses all of the contents of a source file or a summary file;
  2011. it only  uses library  entries if  they  are  referenced  by
  2012. source code or a summary file.
  2013.  
  2014.     An index  file contains partial command lines to be used
  2015. by LINT  in its  operations.   These command  lines can name
  2016. source files  as  input,  but  not  summary  files  or  LINT
  2017. libraries.
  2018.  
  2019.     When  both   an  Output=  and  libraryName=  option  are
  2020. specified, LINT  creates a LINT library.  If only Output= is
  2021. specified, LINT  creates a  summary file.  If Output= is not
  2022. specified, LINT  examines a  source file or summary file for
  2023. problem spots  and writes  its diagnostics  to the  standard
  2024. output.
  2025.  
  2026.  
  2027. _M_u_l_t_i_p_l_e_ _D_e_f_i_n_i_t_i_o_n_s
  2028.  
  2029.     If LINT  finds two  definitions for the same function or
  2030. external variable,  it always  outputs a diagnostic message.
  2031. If the  two definitions are both in normal source code, LINT
  2032. arbitrarily chooses  the first  definition it  finds as  the
  2033. "correct" definition,  and issues  diagnostics for any later
  2034. deviations  from  this  definition.    If  one  of  the  two
  2035. definitions is  in a LINT library and the other is in normal
  2036. source code,  LINT chooses  the non-library  version as  the
  2037. "correct" definition.   In  this way, a definition in normal
  2038. source code overrides a library definition.
  2039.  
  2040.  
  2041.  
  2042.  
  2043. Page 32                                       November, 1995
  2044.  
  2045.  
  2046.  
  2047. Thinkage Ltd.                          LINT Reference Manual
  2048.  
  2049.  
  2050.  
  2051.  
  2052. _C_o_n_f_i_g_u_r_a_t_i_o_n_ _F_i_l_e_s
  2053.  
  2054.     A configuration  file consists of a series of directives
  2055. that control  the behavior of LINT.  The possible directives
  2056. are explained below.
  2057.  
  2058. define name string
  2059.      has the  same format and purpose as a ##ddeeffiinnee directive
  2060.      in normal  C code.  It creates a manifest or macro with
  2061.      the given value.
  2062.  
  2063. inline includefile
  2064.      lets you  simulate an include file.  When LINT finds an
  2065.      inline directive,  it begins  to gather  input lines up
  2066.      until  the   first  line   consisting  of  only  a  '#'
  2067.      character.  For example, in
  2068.  
  2069.         inline sim.h
  2070.         extern int junk1;
  2071.         extern int junk2;
  2072.         #
  2073.  
  2074.      LINT collects  the two declarations and associates them
  2075.      with the  name "sim.h".   If  a  program  contains  the
  2076.      directive,
  2077.  
  2078.         #include <sim.h>
  2079.  
  2080.      LINT takes  the gathered  text and  includes it at that
  2081.      point in  the program,  as  if  it  had  come  from  an
  2082.      included file.
  2083.  
  2084. map includename1 includename2
  2085.      says that all references of the form
  2086.  
  2087.         #include includename1
  2088.  
  2089.      should be converted to
  2090.  
  2091.         #include includename2
  2092.  
  2093. null includefile
  2094.      tells LINT  to  ignore  all  #include  directives  that
  2095.      attempt to include the specified file.
  2096.  
  2097. search pathname
  2098.      is equivalent  to Include=pathname  on the LINT command
  2099.      line.
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105. November, 1995                                       Page 33
  2106.  
  2107.  
  2108.  
  2109. LINT Reference Manual                          Thinkage Ltd.
  2110.  
  2111.  
  2112.  
  2113. system_search pathname
  2114.      is equivalent  to StandardInclude=pathname  on the LINT
  2115.      command line.
  2116.  
  2117. _I_n_s_t_a_l_l_a_t_i_o_n_ _F_i_l_e_s_:
  2118.     An  installation   file  specifies   the  pathnames  for
  2119. software and  data files  used by  LINT.  Installation files
  2120. are text files made up of comment lines and option lines.
  2121.  
  2122. Comment lines:
  2123.      Any line  whose first  non-blank character is # will be
  2124.      taken as  a comment.   Blank  lines are also considered
  2125.      comments.
  2126.  
  2127. Option lines:
  2128.      Option lines have the format
  2129.  
  2130.           Keyword=pathname
  2131.  
  2132.      In this  documentation, keywords  are written with some
  2133.      letters in  upper case and some in lower case.  You may
  2134.      abbreviate keywords  by omitting  any  or  all  of  the
  2135.      letters shown in lower case.  The remaining letters may
  2136.      be  entered   in  either   upper  or  lower  case;  the
  2137.      documentation simply  uses upper  case  to  show  which
  2138.      characters may not be omitted.
  2139.  
  2140.     In this version of LINT, possible option lines are:
  2141.  
  2142. Include=pathname
  2143.      gives the directory containing the LINT include files.
  2144.  
  2145. Library=pathname
  2146.      gives the directory containing the LINT libraries.
  2147.  
  2148. Program=pathname
  2149.      gives the  directory  containing  the  LINT  executable
  2150.      files (CPP, and so on).
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167. Page 34                                       November, 1995
  2168.