⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lint

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 3 页
字号:
In these operations,\fBchar\fR, \fBshort\fR, \fBint\fR, \fBlong\fR, \fBunsigned\fR, \fBfloat\fR, and \fBdouble\fR types may be freely intermixed.The types of pointers must agree exactly,except that arrays of \fIx\fR's can, of course, be intermixed with pointers to \fIx\fR's..PPThe type checking rules also require that, in structure references, theleft operand of the \(em> be a pointer to structure, the left operand of the \fB.\fRbe a structure, and the right operand of these operators be a memberof the structure implied by the left operand.Similar checking is done for references to unions..PPStrict rules apply to function argument and return valuematching.The types \fBfloat\fR and \fBdouble\fR may be freely matched,as may the types \fBchar\fR, \fBshort\fR, \fBint\fR, and \fBunsigned\fR.Also, pointers can be matched with the associated arrays.Aside from this, all actual arguments must agree in type with their declared counterparts..PPWith enumerations, checks are made that enumeration variables or members are not mixedwith other types, or other enumerations,and that the only operations applied are =, initialization, ==, !=, and function arguments and return values..SHType Casts.PPThe type cast feature in C was introduced largely as an aidto producing more portable programs.Consider the assignment.DSp = 1 ;.DEwhere.I pis a character pointer..I Lintwill quite rightly complain.Now, consider the assignment.DSp = (char \(**)1 ;.DEin which a cast has been used toconvert the integer to a character pointer.The programmer obviously had a strong motivationfor doing this, and has clearly signaled his intentions.It seems harsh for.I lintto continue to complain about this.On the other hand, if this code is moved to anothermachine, such code should be looked at carefully.The.B \-cflag controls the printing of comments about casts.When.B \-cis in effect, casts are treated as though they were assignmentssubject to complaint; otherwise, all legal casts are passed without comment,no matter how strange the type mixing seems to be..SHNonportable Character Use.PPOn the PDP-11, characters are signed quantities, with a rangefrom \-128 to 127.On most of the other C implementations, characters take on only positivevalues.Thus,.I lintwill flag certain comparisons and assignments as beingillegal or nonportable.For example, the fragment.DSchar c;	...if( (c = getchar(\|)) < 0 ) .....DEworks on the PDP-11, butwill fail on machines where characters always takeon positive values.The real solution is to declare.I can integer, since.I getcharis actually returninginteger values.In any case,.I lintwill say``nonportable character comparison''..PPA similar issue arises with bitfields; when assignmentsof constant values are made to bitfields, the field maybe too small to hold the value.This is especially true becauseon some machines bitfields are considered as signedquantities.While it may seem unintuitive to considerthat a two bit field declared of type.B intcannot hold the value 3, the problem disappearsif the bitfield is declared to have type.B unsigned ..SHAssignments of longs to ints.PPBugs may arise from the assignment of.B longtoan.B int ,which loses accuracy.This may happen in programswhich have been incompletely converted to use.B typedefs .When a.B typedefvariableis changed from \fBint\fR to \fBlong\fR,the program can stop working becausesome intermediate results may be assignedto \fBints\fR, losing accuracy.Since there are a number of legitimate reasons forassigning \fBlongs\fR to \fBints\fR, the detectionof these assignments is enabledby the.B \-aflag..SHStrange Constructions.PPSeveral perfectly legal, but somewhat strange, constructionsare flagged by.I lint;the messages hopefully encourage better code quality, clearer style, andmay even point out bugs.The.B \-hflag is used to enable these checks.For example, in the statement.DS\(**p++ ;.DEthe \(** does nothing; this provokes the message ``null effect'' from.I lint .The program fragment.DSunsigned x ;if( x < 0 ) ....DEis clearly somewhat strange; thetest will never succeed.Similarly, the test.DSif( x > 0 ) ....DEis equivalent to.DSif( x != 0 ).DEwhich may not be the intended action..I Lintwill say ``degenerate unsigned comparison'' in these cases.If one says.DSif( 1 != 0 ) .....DE.I lintwill report``constant in conditional context'', since the comparisonof 1 with 0 gives a constant result..PPAnother constructiondetected by.I lintinvolvesoperator precedence.Bugs which arise from misunderstandings about the precedenceof operators can be accentuated by spacing and formatting,making such bugs extremely hard to find.For example, the statements.DSif( x&077 == 0 ) ....DEor.DSx<\h'-.3m'<2 + 40.DEprobably do not do what was intended.The best solution is to parenthesize such expressions,and.I lintencourages this by an appropriate message..PPFinally, when the.B \-hflag is in force.I lintcomplains about variables which are redeclared in inner blocksin a way that conflicts with their use in outer blocks.This is legal, but is considered by many (including the author) tobe bad style, usually unnecessary, and frequently a bug..SHAncient History.PPThere are several forms of older syntax which are being officiallydiscouraged.These fall into two classes, assignment operators and initialization..PPThe older forms of assignment operators (e.g., =+, =\-, . . . )could cause ambiguous expressions, such as.DSa  =\-1 ;.DEwhich could be taken as either.DSa =\-  1 ;.DEor.DSa  =  \-1 ;.DEThe situation is especially perplexing if thiskind of ambiguity arises as the result of a macro substitution.The newer, and preferred operators (+=, \-=, etc. )have no such ambiguities.To spur the abandonment of the older forms,.I lintcomplains about these old fashioned operators..PPA similar issue arises with initialization.The older language allowed.DSint  x  \fR1 ;.DEto initialize.I xto 1.This also caused syntactic difficulties: for example,.DSint  x  ( \-1 ) ;.DElooks somewhat like the beginning of a function declaration:.DSint  x  ( y ) {  . . ..DEand the compiler must read a fair ways past.I xin order to sure what the declaration really is..Again, the problem is even more perplexing when theinitializer involves a macro.The current syntax places an equals sign between thevariable and the initializer:.DSint  x  =  \-1 ;.DEThis is free of any possible syntactic ambiguity..SHPointer Alignment.PPCertain pointer assignments may be reasonable on some machines,and illegal on others, due entirely toalignment restrictions.For example, on the PDP-11, it is reasonableto assign integer pointers to double pointers, sincedouble precision values may begin on any integer boundary.On the Honeywell 6000, double precision values must beginon even word boundaries;thus, not all such assignments make sense..I Linttries to detect cases where pointers are assigned to otherpointers, and such alignment problems might arise.The message ``possible pointer alignment problem''results from this situation whenever either the.B \-por.B \-hflags are in effect..SHMultiple Uses and Side Effects.PPIn complicated expressions, the best order in which to evaluatesubexpressions may be highly machine dependent.For example, on machines (like the PDP-11) in which the stackruns backwards, function arguments will probably be best evaluatedfrom right-to-left; on machines with a stack running forward,left-to-right seems most attractive.Function calls embedded as arguments of other functionsmay or may not be treated similarly to ordinary arguments.Similar issues arise with other operators which have side effects,such as the assignment operators and the increment and decrement operators..PPIn order that the efficiency of C on a particular machine not beunduly compromised, the C language leaves the orderof evaluation of complicated expressions up to thelocal compiler, and, in fact, the various C compilers have considerabledifferences in the order in which they will evaluate complicatedexpressions.In particular, if any variable is changed by a side effect, andalso used elsewhere in the same expression, the result is explicitly undefined..PP.I Lintchecks for the important special case wherea simple scalar variable is affected.For example, the statement.DS\fIa\fR[\fIi\|\fR] = \fIb\fR[\fIi\fR++] ;.DEwill draw the complaint:.DSwarning: \fIi\fR evaluation order undefined.DE.SHImplementation.PP.I Lintconsists of two programs and a driver.The first program is a version of thePortable C Compiler.[Johnson Ritchie BSTJ Portability Programs System.].[Johnson portable compiler  1978.]which is the basis of theIBM 370, Honeywell 6000, and Interdata 8/32 C compilers.This compiler does lexical and syntax analysis on the input text,constructs and maintains symbol tables, and builds trees for expressions.Instead of writing an intermediate file which is passed toa code generator, as the other compilersdo,.I lintproduces an intermediate file which consists of lines of ascii text.Each line contains an external variable name,an encoding of the context in which it was seen (use, definition, declaration, etc.),a type specifier, and a source file name and line number.The information about variables local to a function or fileis collectedby accessing the symbol table, and examining the expression trees..PPComments about local problems are produced as detected.The information about external names is collectedonto an intermediate file.After all the source files and library descriptions havebeen collected, the intermediate file is sortedto bring all information collected about a given externalname together.The second, rather small, program then reads the linesfrom the intermediate file and compares all of thedefinitions, declarations, and uses for consistency..PPThe driver controls thisprocess, and is also responsible for making the options availableto both passes of.I lint ..SHPortability.PP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -