Do you trust the "indent" program?

Arnold Robbins arnold at audiofax.com
Thu Dec 27 05:24:31 AEST 1990


>In article <12184 at sybase.sybase.com> forrest at sybase.com writes:
>> Do you trust 'indent'
>> enough to run it on all your source file without making any mistakes?

Personally, no.  See below for what I'd do if I had thousands of lines of
code to massage.

In article <11742 at alice.att.com> ark at alice.UUCP () writes:
>I don't need to -- I can compile my programs before and after
>and compare the object files.  If they're not identical,
>something's broken.

Andrew is fortunate enough to be running on a Unix system that doesn't
use COFF for it's object files --- COFF files have a timestamp in them.
If you know where it is (I don't), you can arrange to strip off the
COFF header and then compare the objects, but it is not as simple an
operation as it used to be.

A better, more useful technique would be to use lex/flex to write a
C scanner that produced a stream of tokens, one per line.  Run it against
the before and after versions, and then use diff on the two outputs.

	main() { printf("hello, world\n"); }

and
	main (
	) {
	printf
	(
	"hello, world\n"
	) ; }

should both produce (collapsed to save space)

	ident open-p close-p open-brace ident open-p string-const
	close-p semi-colon close-brace

as their token streams.  Comments should be noted, as should preprocessor
lines and such.  It's about a day's job to do well.  Some versions of
indent were notorious for turning

	i =-1;	/* XXX --- could be old style assign op */

into

	i -= 1;

which of course is wrong.  Comparing the tokenized version of the code
would make catching this sort of change much easier.

Even if there were a few errors of this sort, using indent and then cleaning
up after it would still be a win over reformatting code by hand.
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold at audiofax.com Phone:   +1 404 933 7612 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins



More information about the Comp.lang.c mailing list