[comp.unix.wizards] C Compiler Bug

mnc@m10ux.UUCP (04/27/87)

Here is a nasty little bug I just ran into with the Sys V R2 (VAX) C
compiler and the Sun C compiler (but it does not exist on 4.3 BSD).
Consider:

	extern void f(), (*fp)();
	int x;
	main() {
		g(x ? f :  fp);
		g(x ? f : *fp);
	}

Both of the uses of the "? :" operator produce the message "operands of
: have incompatible types".  Changing "void" to any other type makes
both error messages go away.  Notice that there is no attempt to use
a void value in the above expression.  Since this code is likely to
occur in any C program that passes procedures (i.e. void functions) as
arguments, I don't understand how the bug could have persisted this long.
The only work-around I can think of (besides changing the declaration of
f and fp) is to use "if - else" instead of "? - :".
-- 
Michael Condict		{ihnp4|vax135|cuae2}!m10ux!mnc
AT&T Bell Labs		(201)582-5911    MH 3B-416
Murray Hill, NJ

dave@runx.ips.oz (Dave Horsfall) (05/05/87)

cur in any C program that passes procedures (i.e. void functions) as
> arguments, I don't understand how the bug could have persisted this long.
> The only work-around I can think of (besides changing the declaration of
> f and fp) is to use "if - else" instead of "? - :".
> -- 
> Michael Condict		{ihnp4|vax135|cuae2}!m10ux!mnc
> AT&T Bell Labs		(201)582-5911    MH 3B-416
> Murray Hill, NJ

Oh no!  Someone else just discovered this "bug".  Now for another
scintillating discussion for the next several weeks on whether
a "void" expression actually returns a value or not ...

Perhaps this ought to be included in the list of hints to new users
on what not to post, along with any proofs of 1=0.
--
Dave Horsfall (VK2KFU)		 ISD: +61 2 438-3544   FAX: 439-7036
UNIX Technical Support		 STD:  (02) 438-3544   TLX:  AA27411
NEC Information Systems Aust.	 ACS: dave@astra.necisa.oz (also CSNET) 
3rd Floor, 99 Nicholson St 	ARPA: dave%astra.necisa.oz@seismo.css.gov
St. Leonards  NSW  2064		UUCP: {enea,hplabs,mcvax,prlb2,seismo, \
AUSTRALIA			ubc-vision,ukc}!munnari!astra.necisa.oz!dave