void casts; and C definition question

Sam Kendall kendall at wjh12.UUCP
Sun Oct 2 07:02:51 AEST 1983

The complaint is that
	(void) f();
is a kludge, that
	(*(void (*)()) f)();	/* or something like that */
is the "real" way to do the former.  Well, I there is nothing wrong
with the former.  A void cast means "throw away a value".

An interesting point here is that the latter is not even guaranteed
to work in the C language.  Calling a function with an incorrectly
specified type usually works, but on some compilers (National
Semiconductor's 16032 C compiler, for instance), if f() returns a
structure, then it must be declared to do so for a call to work,
since the address of where to put the return value is passed as the
first arg of the function.

Many programs do not declare the return type of functions correctly;
for instance, it is common to leave off a
	char *strcpy();
definition if the return value is never used.  My question is this:  
What should the language say about calling functions with incorrectly
declared return values?  We cannot guarantee that it will work with
functions returning structures.  But should it otherwise?  Many programs
(unfortunately) depend on it.

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

More information about the Comp.lang.c mailing list