questions from using lint

Root Boy Jim rbj at icst-cmr
Sat May 3 07:28:02 AEST 1986


	Re: "lint" not being as smart as Root Boy Jim

Gee, I hope not. After it's *only* a *program* (and I'm not? :-)
	
	That's really silly.  I write C code such that I expect absolutely
	NO warnings from "lint" (except for malloc pointer type-cast, which
	is unavoidable at present); then if I get any "lint" warnings, they
	indicate BUGS that must be fixed.  This is tremendously helpful.

Not really. I will give you one good example of a technique that is NOT a
bug, altho it may make you shudder somewhat. I have ranted about C using
a one statement model for its control statements instead of an explicit
end statement. Compound statements are bounded by braces instead. Yuk!
Fortunately, there is the comma operator. This allows the following:

	Most People			Your's Truly

	if (c) {			if (c)
		w = y;				w = x,
		y = z;				y = z;
	}				/* look ma, no brace */

Other things you will see in my code are:

	if (argc < 2)
		exit((printf("usage: foo bar\n"),1));
or even:	exit(1,printf("usage: foo bar\n"));
	
Sufficeth to say that I use a lot of commas in my code. Unfortunately,
I cannot do this if either statement is a control struxure, *except* return.

	Most People			Your's Truly

	if (c) {			if (c)
		w = y;				return w = x,
		return;
	}				/* look ma, no brace */

When I want to return a *real* value, I use `return(exp)' using *explicit*
parens. I only do this in void funxions of course. I cannot see *any*
implementation doing either of the following:

	1) barfing because I returned an *extra* value sometimes
	2) barfing because I added an extra argument

Now you may claim that this is `bad programming practice', but I claim
that it is just a convention, just like #defines are usually capitalized.
You may not like either one, but I claim this is portable. And, it is
meaningful to me.

	I find that there are very few "inherently nonportable" applications.
	Even when an application is designed to use specific hardware,
	portable programming techniques contribute to better code quality.

This is probably true. He who lives by the trick usually dies by it.
On the other hand, I just tried to port the System V date to BSD, and
it mumbled somthing about timezones not being defined. My point is
that even the simplest things usually require *some* diddling.
	
	Lint-free coding comes naturally after a bit of practice.  I find
	it no burden at all, and hardly have to think about it.  Indeed,
	it helps organize my use of complicated data types so that I get
	the code right (and portable!) the first time.
	
Yes, but it all depends on what you're willing to put up with. I find it
terribly ugly having to cast printf's or close's to void. And as
someone pointed out, assignments return a value too, so should we cast
them to void as well? Oh yeah, assignment is `different'.

	(Root Boy) Jim Cottrell		<rbj at cmr>
	"One man gathers what another man spills"



More information about the Comp.lang.c mailing list