When does void make code less readable?

Mark Brader msb at lsuc.UUCP
Mon Feb 18 03:46:26 AEST 1985


Consider the function strcpy.  The manual here declares this as:

     char *strcpy(s1, s2)
     char *s1, *s2;

The return value here is just a copy of the input value s1, provided
on the off-chance that it'll be useful to the calling program.  I claim
that all functions that don't otherwise return a value should strive
to return a might-be-useful value.  Then when you see a function call
whose result is unassigned, you know a return value is being ignored.
I think (void) should be reserved for really unusual cases, as documentation
that you really meant to do that.

I do support the use of lint, but I don't like (void).  It just clashes
with the language's style, to my mind.  After all, we can write:

	a = ++b;
or:
	++b;

but I don't want to write the latter as:

	(void) ++b;

everywhere.  What's the difference between this an a function call:

	increment(&b);
?

Mark Brader



More information about the Comp.lang.c mailing list