void avoidance

Sam Kendall kendall at wjh12.UUCP
Mon Oct 10 00:59:19 AEST 1983


Damon, what is your objection to void casts?  If your objection is that

	int f();
	...
	(void) f();

is redundant, since the void cast specifies something ("throw away
the result") which would be apparent anyway, you are right, in that
void casts are no help to compilers.  They are useful for lint.  A
void cast says to lint, "I'm not using the value of this expression,
and I'm well aware of it, so shut up."

As for `(void) ++i', there is nothing wrong with it, but lint chooses
not to complain about throwing away the value of an assignment operator
(including ++ and --) anyway, so the void cast serves no purpose.

There are rules about void specified in later versions of the C Reference
Manual; unfortunately Prentice-Hall still publishes the original.  (I
think there are some bad decisions in those rules, but that is another
story.)

	Sam Kendall		  {allegra,ihnp4}!wjh12!kendall
	Delft Consulting Corp.	    decvax!genrad!wjh12!kendall



More information about the Comp.lang.c mailing list