tim@mtxinu.UUCP (Tim Wood) (03/19/88)
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!timbrian@bucc2.UUCP (03/23/88)
> /* Written 7:55 pm Mar 18, 1988 by mtxinu.UUCP!tim in bucc2:comp.lang.c */ > /* ---------- "'BSD C compiler bug'" ---------- */ > 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 = I _think_ changing those NULL's on lines 8,9 to (unsigned char **) NULL will eliminate these warnings. ............................................................................... When the going gets weird, the weird turn pro. Brian Michael Wendt UUCP: {cepu,ihnp4,uiucdcs,noao}!bradley!brian Bradley University ARPA: cepu!bradley!brian@seas.ucla.edu (309) 691-5175 ICBM: 40 40' N 89 34' W