Why use (void) func() ?
Dave Lee
dave at dptechno.uucp
Sat Sep 22 07:15:19 AEST 1990
This is a bone I've been thinking about for some time.
Given a simple function like :
int func(){ ... }
Whose return value I rarely care about --- say printf().
Why should I go to the extra trouble to write
(void) printf("hello world\n");
Instead of
printf("hello world\n");
IMHO, one of the great beauties of C is not distinguishing between
procedure and function calls.
The possible reasons I have deduced are:
1. shut up lint.
2. shut up the compiler
To both 1 and 2 I reply:
If I wanted to check the return value, I would have.
This is not the sort of thing that results from a typo or unconcious omission.
I never type
func_call();
When I mean
if( func_call() == whatever ) ...;
I never "accidently" ommit a check for return value, though I may be lazy
and decide to omit one.
I believe this is a programming consideration, not a language one.
Any comments on this? Of what real value is the extra "(void)", when
IMHO omitting it is easier to read, shorter, and has identical meaning to
the compiler.
--
Dave Lee
uunet!dptechno!dave
More information about the Comp.lang.c
mailing list