void

Bjarne Stroustrup bs at alice.UucP
Sat Aug 2 11:30:23 AEST 1986


I tried a little program on the three 8th Edition UNIX C compilers:

	cc	- the standard C compiler
	cyntax	- a very competent C checker
	CC	- the C++ compiler

void f1(), f2();
int f3();

void h()
{
	int i;			/* 	cc	cyntax	CC	*/
	f1();			/*				*/
	i = f1();		/*	error	error	error	*/
	f1(),f2();		/*				*/
	f1(),f3();		/*				*/
	i = (f1(),f2());	/*	error	error	error	*/
	i = (f1(),f3());	/*				*/
	i?f1():f3();		/*	error			*/
	i = i?f1():f2();	/*	error	error	error	*/
	i = i?f1():f3();	/*	error	error	error	*/
}

They don't like assigning a void to an int.
They don't mind an operand of ``,'' being void as long as it is not
assigned to anything.
They all agree that the second and third operands of ?: must be of the
same type (modulo standard conversions).
cc insists that an operand of ?: must not be void even if it is not used;
cyntax and CC disagree.

I think cyntax and CC are right. It is inconsistent to allow an operand
to ``,'' to be void provided it is not used and at the same time to disallow
an operand of ``?;'' from being void even when it is not used. I think cc's
behaviour is a leftover from the days where there were no void.



More information about the Comp.lang.c mailing list