### Question 17.5

I came across some code that puts a `(void)` cast before each call to `printf`. Why?

`printf` does return a value, though few programs bother to check the return values from each call. Since some compilers (and `lint`) will warn about discarded return values, an explicit cast to `(void)` is a way of saying ``Yes, I've decided to ignore the return value from this call, but please continue to warn me about other (perhaps inadvertently) ignored return values.'' It's also common to use `void` casts on calls to `strcpy` and `strcat`, since the return value is never surprising.

References: K&R2 Sec. A6.7 p. 199
Rationale Sec. 3.3.4
H&S Sec. 6.2.9 p. 172, Sec. 7.13 pp. 229-30

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback