'BSD C compiler bug'

Tim Wood tim at mtxinu.UUCP
Sat Mar 19 11:55:52 AEST 1988


Subject: BSD C compiler bug?
Newsgroups: comp.unix,comp.lang.c
Keywords: comma notation


There seems to be a bug with comma notation in BSD C.  (It shows up
on the Ultrix, MORE/BSD and Sun compilers, FYI).

This program:
     1		# define NULL	0
     2		main()
     3		{
     4			unsigned char	**foo;
     5			int		fn();
     6	
     7			foo = NULL;
     8			foo = (NULL, NULL);
     9			foo = ( !foo ? NULL : (fn(2), NULL) );
    10		}
    11	
    12		fn(a)
    13		int	a;
    14		{ return (a); }
    15	
gets 'cc' errors:
"comma.c", line 8: warning: illegal combination of pointer and integer, op =
"comma.c", line 9: warning: illegal combination of pointer and integer, op =

Removing the parentheses from line 8 results in:
"comma.c", line 9: warning: illegal combination of pointer and integer, op =

Leaving line 8 alone and replacing line 9 with:
		foo = ( !foo ? NULL : fn(2), NULL );
or
		foo = !foo ? NULL : fn(2), NULL;
gives the same errors (for lines 8 and 9).

K&R say that the result type & value of a comma expression are that of the
second term, which is NULL (0) in all cases here.  And NULL is assignment
compatible to all pointers.
Or am I missing something?

-TW

{ihnp4!pacbell,pyramid,{uunet,ucbvax}!mtxinu}!sybase!tim

-- 
{ihnp4!pacbell,pyramid,{uunet,ucbvax}!mtxinu}!sybase!tim



More information about the Comp.unix.questions mailing list