1 / 14

CS 501

CS 501. Lint, Purify, and Coding Standards Eric Melin September 26,1999. Lint. Lint is a semantic checker that identifies potential bugs in C programs Lint is a mistake!

setliff
Download Presentation

CS 501

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 501 Lint, Purify, and Coding Standards Eric Melin September 26,1999

  2. Lint • Lint is a semantic checker that identifies potential bugs in C programs • Lint is a mistake! • In the early days of C on UNIX complete semantic checking was removed from the C compiler as a design decision. This allowed for smaller, simpler, and faster compilers at the expense of potentially buggy code. • Lint exists on UNIX systems (but not LINUX) • Most modern ANSI C compilers include Lint semantic checking functionality but only some of Lint’s other features • Use Lint Early and Often!

  3. What does Lint Do? • Checks for consistency in function use across multiple files • Finds • bugs • non-portable code • wasteful code • Typical Bugs Detected include • Argument types transposed between function and call • Function with wrong number of arguments takes junk from stack • Variables being used before set or never used

  4. More about Lint • See Unix man page • OR “Checking C Programs with lint” By Ian F. Darwin

  5. Purify • Purify is a tool for locating runtime errors in a C/C++ program • Purify can find • Array bounds errors • Accesses through dangling pointers • Uninitialized memory reads • Memory allocation errors • Memory leaks • Purify is available on Windows and UNIX systems and is a product of Rational Software www.rational.com

  6. How Purify Works • Purify instruments a program by adding protection instructions around every load and store operation • When program is executed a viewer will be created to display errors as they happen • Purify is flexible and can be run standalone with any executable (written in C) or within a debugging environment like Visual Studio • Purify is customizable and can be set to ignore certain types of errors

  7. How to Use Purify • add purify command to link command • program: $(OBJS) purify [-option ...] $(CC) $(CFLAGS) -o\ program $(OBJS) $(LIBS) • OR run purify in Visual Studio • OR load file in purify executable

  8. Coding Standards • Why Have Coding Standards? • Greater consistency between multiple developers • Easier to develop and maintain • Saves time and money • The Prime Directive • Document every time you go against a standard • No standard is perfect for every application, but failure to comply with your standards requires a comment

  9. Ambler’s Law of Standards • Industry Standards > organizational standards > project standards > no standards • The more commonly accepted a standard the easier it is for team members to communicate • Invent standards when necessary, but don’t waste time creating something that you won’t be able to use later. • All languages have recommended coding standards available. It is well worth your effort to find and use industry standards • Push for organizational standards whenever possible

  10. Good Coding Style • Names • Use full English descriptors • Use mixed case to make names readable • Use abbreviations sparingly and consistently • Avoid long names • Avoid leading/trailing underscores • Documentation • Document the purpose of every variable • Document why something is done not just what

  11. Accessors • use getVar() and setVar() functions on all class variable unless class is being used solely as a data structure • Member Functions Documentation • What and why member function does what it does • Parameters / return value • How function modifies object • Preconditions /Postconditions • Concurrency issues • Restrictions • Internal Documentation • Control Structures • Why as well as what the code does • Difficult or complex code • Processing order

  12. Examples of Coding Standards • http://www.ambysoft.com/javaCodingStandards.html • http://www.swtech.com/java/codestd/ • http://ccs.hst.nasa.gov/ccspages/policies/standards/coding_standards.html • http://www.scriptics.com/doc/styleGuide.pdf

More Related