(void) and printf

Mark Brukhartz mark at laidbak.UUCP
Wed Aug 7 18:37:23 AEST 1985


> Granted, there are occasions when you want to test the return values
> of the I/O functions.  But if you think (void) printf() is bad, how
> about:
> 
>     (void) sprintf(str,"foo");
> 
> How often does sprintf() return an error indication on YOUR system?
> 
> 		Gary

It appears that sprintf() comes in several flavors:

	o System V (...chocolate) returns the length of the generated string.
	o 4.2BSD (...strawberry) returns a pointer to the generated string.
	o Version 7 (...vanilla) does not document a return value.

Lint should certainly complain about ignored return values from
functions which might fail, such as read(), write() and printf().
Some other functions, like getlogin(), serve no obvious purpose
when their return values are ignored. Thus, they should also be
watched closely by lint.

Many functions manipulate data via pointers or global variables,
returning convenient values for nesting purposes; strcpy() and
strcat() come to mind. It is safe (and quite commonplace) to
ignore the return value from such a function.

We could make lint recognize (yet another) "special comment" to
shut off "ignored return value" complaints for a given function.
For example, "/* MAYIGNORE */" before a function definition (or
lint library function definition stub) could stop complaints of
ignored return value on *all* calls to the given function.

Given that (void) casts should still be required with printf(),
since it can truly fail, is this problem really worthy of another
lint "special comment"?

					Mark Brukhartz
					..!ihnp4!laidbak!mark



More information about the Comp.lang.c mailing list