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

📄 lint

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 3 页
字号:
C on the Honeywell and IBM systems is used, in part, to write system code for the host operating system.This means that the implementation of C tends to follow local conventions rather thanadhere strictly to.UXsystem conventions.Despite these differences, many C programs have been successfully moved to GCOS and the various IBMinstallations with little effort.This section describes some of the differences between the implementations, anddiscusses the.I lintfeatures which encourage portability..PPUninitialized external variables are treated differently in differentimplementations of C.Suppose two files both contain a declaration without initialization, such as.DSint a ;.DEoutside of any function.The.UXloader will resolve these declarations, and cause only a single word of storageto be set aside for \fIa\fR.Under the GCOS and IBM implementations, this is not feasible (for various stupid reasons!)so each such declaration causes a word of storage to be set aside and called \fIa\fR.When loading or library editing takes place, this causes fatal conflicts which preventthe proper operation of the program.If.I lintis invoked with the \fB\-p\fR flag,it will detect such multiple definitions..PPA related difficulty comes from the amount of information retained about external names during theloading process.On the.UXsystem, externally known names have seven significant characters, with the upper/lowercase distinction kept.On the IBM systems, there are eight significant characters, but the case distinctionis lost.On GCOS, there are only six characters, of a single case.This leads to situations where programs run on the.UXsystem, but encounter loaderproblems on the IBM or GCOS systems..I Lint.B \-pcauses all external symbols to be mapped to one case and truncated to six characters,providing a worst-case analysis..PPA number of differences arise in the area of character handling: characters in the.UXsystem are eight bit ascii, while they are eight bit ebcdic on the IBM, andnine bit ascii on GCOS.Moreover, character strings go from high to low bit positions (``left to right'')on GCOS and IBM, and low to high (``right to left'') on the PDP-11.This means that code attempting to construct stringsout of character constants, or attempting to use characters as indicesinto arrays, must be looked at with great suspicion..I Lintis of little help here, except to flag multi-character character constants..PPOf course, the word sizes are different!This causes less trouble than might be expected, at least whenmoving from the.UXsystem (16 bit words) to the IBM (32 bits) or GCOS (36 bits).The main problems are likely to arise in shifting or masking.C now supports a bit-field facility, which can be used to write much ofthis code in a reasonably portable way.Frequently, portability of such code can be enhanced byslight rearrangements in coding style.Many of the incompatibilities seem to have the flavor of writing.DSx &= 0177700 ;.DEto clear the low order six bits of \fIx\fR.This suffices on the PDP-11, but fails badly on GCOS and IBM.If the bit field feature cannot be used, the same effect can be obtained bywriting.DSx &= \(ap 077 ;.DEwhich will work on all these machines..PPThe right shift operator is arithmetic shift on the PDP-11, and logical shift on mostother machines.To obtain a logical shift on all machines, the left operand can betyped \fBunsigned\fR.Characters are considered signed integers on the PDP-11, and unsigned on the other machines.This persistence of the sign bit may be reasonably considered a bug in the PDP-11 hardwarewhich has infiltrated itself into the C language.If there were a good way to discover the programs which would be affected, C could be changed;in any case,.I lintis no help here..PPThe above discussion may have made the problem of portability seembigger than it in fact is.The issues involved here are rarely subtle or mysterious, at least to theimplementor of the program, although they can involve some work to straighten out.The most serious bar to the portability of.UXsystem utilities has been the inability to mimicessential.UXsystem functions on the other systems.The inability to seek to a random character position in a text file, or to establish a pipebetween processes, has involved far more rewritingand debugging than any of the differences in C compilers.On the other hand,.I linthas been very helpfulin moving the.UXoperating system and associatedutility programs to other machines..SHShutting Lint Up.PPThere are occasions whenthe programmer is smarter than.I lint .There may be valid reasons for ``illegal'' type casts,functions with a variable number of arguments, etc.Moreover, as specified above, the flow of control informationproduced by.I lintoften has blind spots, causing occasional spuriousmessages about perfectly reasonable programs.Thus, some way of communicating with.I lint ,typically to shut it up, is desirable..PPThe form which this mechanism should take is not at all clear.New keywords would require current and old compilers torecognize these keywords, if only to ignore them.This has both philosophical and practical problems.New preprocessor syntax suffers from similar problems..PPWhat was finally done was to cause a number of wordsto be recognized by.I lintwhen they were embedded in comments.This required minimal preprocessor changes;the preprocessor just had to agree to pass commentsthrough to its output, instead of deleting themas had been previously done.Thus,.I lintdirectives are invisible to the compilers, andthe effect on systems with the older preprocessorsis merely that the.I lintdirectives don't work..PPThe first directive is concerned with flow of control information;if a particular place in the program cannot be reached,but this is not apparent to.I lint ,this can be asserted by the directive.DS/* NOTREACHED */.DEat the appropriate spot in the program.Similarly, if it is desired to turn offstrict type checking forthe next expression, the directive.DS/* NOSTRICT */.DEcan be used; the situation reverts to theprevious default after the next expression.The.B \-vflag can be turned on for one function by the directive.DS/* ARGSUSED */.DEComplaints about variable number of arguments in calls to a functioncan be turned off by the directive.DS/* VARARGS */.DEpreceding the function definition.In some cases, it is desirable to check thefirst several arguments, and leave the later arguments unchecked.This can be done by following the VARARGS keyword immediatelywith a digit giving the number of arguments which should be checked; thus,.DS/* VARARGS2 */.DEwill cause the first two arguments to be checked, the others unchecked.Finally, the directive.DS/* LINTLIBRARY */.DEat the head of a file identifies this file asa library declaration file; this topic is worth asection by itself..SHLibrary Declaration Files.PP.I Lintaccepts certain library directives, such as.DS\-ly.DEand tests the source files for compatibility with these libraries.This is done by accessing library description files whosenames are constructed from the library directives.These files all begin with the directive.DS/* LINTLIBRARY */.DEwhich is followed by a series of dummy functiondefinitions.The critical parts of these definitionsare the declaration of the function return type,whether the dummy function returns a value, andthe number and types of arguments to the function.The VARARGS and ARGSUSED directives canbe used to specify features of the library functions..PP.I Lintlibrary files are processed almost exactly like ordinarysource files.The only difference is that functions which are defined on a library file,but are not used on a source file, draw no complaints..I Lintdoes not simulate a full library search algorithm,and complains if the source files contain a redefinition ofa library routine (this is a feature!)..PPBy default,.I lintchecks the programs it is given against a standard libraryfile, which contains descriptions of the programs whichare normally loaded whena C programis run.When the.B -pflag is in effect, another file is checked containingdescriptions of the standard I/O library routineswhich are expected to be portable across various machines.The.B -nflag can be used to suppress all library checking..SHBugs, etc..PP.I Lintwas a difficult program to write, partiallybecause it is closely connected with matters of programming style,and partially because users usually don't notice bugs which cause.I lintto miss errors which it should have caught.(By contrast, if.I lintincorrectly complains about something that is correct, theprogrammer reports that immediately!).PPA number of areas remain to be further developed.The checking of structures and arrays is rather inadequate;sizeincompatibilities go unchecked,and no attempt is made to match up structure and uniondeclarations across files.Some stricter checking of the use of the.B typedefis clearly desirable, but what checking is appropriate, and howto carry it out, is still to be determined..PP.I Lintshares the preprocessor with the C compiler.At some point it may be appropriate for aspecial version of the preprocessor to be constructedwhich checks for things such as unused macro definitions,macro arguments which have side effects which arenot expanded at all, or are expanded more than once, etc..PPThe central problem with.I lintis the packaging of the information which it collects.There are many options whichserve only to turn off, or slightly modify,certain features.There are pressures to add even more of these options..PPIn conclusion, it appears that the general notion of having twoprograms is a good one.The compiler concentrates on quickly and accurately turning theprogram text into bits which can be run;.I lintconcentrates on issuesof portability, style, and efficiency..I Lintcan afford to be wrong, since incorrectness and over-conservatismare merely annoying, not fatal.The compiler can be fast since it knows that.I lintwill cover its flanks.Finally, the programmer canconcentrate at one stageof the programming process solely on the algorithms,data structures, and correctness of theprogram, and then later retrofit,with the aid of.I lint ,the desirable properties of universality and portability..SG MH-1273-SCJ-unix.bp.[$LIST$.].bp.SHAppendix:   Current Lint Options.PPThe command currently has the form.DSlint\fR [\fB\-\fRoptions ] files... library-descriptors....DEThe options are.IP \fBh\fRPerform heuristic checks.IP \fBp\fRPerform portability checks.IP \fBv\fRDon't report unused arguments.IP \fBu\fRDon't report unused or undefined externals.IP \fBb\fRReport unreachable.B breakstatements..IP \fBx\fRReport unused external declarations.IP \fBa\fRReport assignments of.B longto.B intor shorter..IP \fBc\fRComplain about questionable casts.IP \fBn\fRNo library checking is done.IP \fBs\fRSame as.B h(for historical reasons)

⌨️ 快捷键说明

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