[comp.lang.c] ANSI C lint type tool wanted

markh@tekcrl.LABS.TEK.COM (Mark C Henderson) (07/31/90)

We are looking for an ANSI C lint.

gcc -Wall won't do what we want. In particular it doesn't cover what
is covered by pass 2 in SUN OS lint, i.e. checking the consistency of
declarations across files. 

Is their a way to coax gcc into doing this?

Are there any freely available or commercial lint programmes that will
work with gcc?

In particular I'm aware of Saber C, which certainly has an ANSI mode.
But that is expensive and is overkill.

Please respond by Email as I don't read these groups all that
regularly. Any pointers would be appreciated.

Thanks in advance,

Mark Henderson
Computer Research Laboratory
Tektronix, Inc.
-- 
Mark Henderson, Tektronix, Inc., MS 50-662, P.O. Box 500, Beaverton, OR 97077
Telephone: +1 503 591 5734 (H), +1 503 627 6280 (W)      FAX: +1 503 627 5502
INTERNET: markh@tekcrl.labs.tek.com, 378-4996@mcimail.com  MCI MAIL: 378-4996
TELEX: 6503784996MCI UW   AT&T MAIL: !mchenderson 	DASNet: [DCM1MC]MHEND

arnold@audiofax.com (Arnold Robbins) (07/31/90)

In article <6568@tekcrl.LABS.TEK.COM> markh@tekcrl.LABS.TEK.COM (Mark C Henderson) writes:
>We are looking for an ANSI C lint.
>
>gcc -Wall won't do what we want. In particular it doesn't cover what
>is covered by pass 2 in SUN OS lint, i.e. checking the consistency of
>declarations across files. 
>
>Is their a way to coax gcc into doing this?

Having gone through this recently... the following steps will go a long
way towards what you want.  First though, our functions are all
declared like so:

	int
	name(int p1, float p2 /* and so on */)
	{
		code here
	}

This one line awk script will remove all function bodies from your code.

	cat *.c | awk '/^{/,/^}/  { next } ; /./' > protos.h

Leaving you all the global declarations.  Edit these into a header file
of prototypes and externs that every .c file includes.  Next,

	# create files with lists of function names
	for i in *.c
	do	grep '^[A-Za-z0-9_][A-Za-z0-9_]*(' $i | sed 's/(.*//' > $i.i
	done

	# count the number of files each identifier appears in
	for i in *.i
	do	for j in `cat $i`
		do
			k=`grep -l $j *.c | wc -l`
			if [ $k = 1 ]
			then	echo $j in $i could be static
			fi
		done
	done

This gives you a list of routines that could be made static.  Make the
appropriate changes in your source files and the header with all the
prototypes.  Recompile with gcc -Wall and remove any other problems.

This does not duplicate lint's full functionality, but it certainly
helps.  I too miss having an ANSI lint.
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #220 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold@audiofax.com	Phone: +1 404 933 7600 | number of children.
UUCP:	  emory!audfax!arnold	Fax:   +1 404 933 7606 |   -- Miriam Robbins

gwu@nujoizey.tcs.com (George Wu) (08/02/90)

In article <6568@tekcrl.LABS.TEK.COM>, markh@tekcrl.LABS.TEK.COM (Mark C
Henderson) writes:
|> We are looking for an ANSI C lint.
|> 
|> gcc -Wall won't do what we want. In particular it doesn't cover what
|> is covered by pass 2 in SUN OS lint, i.e. checking the consistency of
|> declarations across files.

     Use header files, ie. something like:

foo.h:
======
extern int func(const char *);

file1.c:
========
#include "foo.h"

int
func(const char* s)
{
}

file2.h:
=======
#include "foo.h"

int
main(int argc, char* argv[])
{
    while (argc) {
        func(argv[argc--]);
    }
}

|> Please respond by Email as I don't read these groups all that
|> regularly. Any pointers would be appreciated.

     I posted and emailed this response.

							George

----
George J Wu                           | gwu@tcs.com or ucbcad!tcs!gwu
Software Engineer                     | 2121 Allston Way, Berkeley, CA, 94704
Teknekron Communications Systems, Inc.| (415) 649-3752