BSD C compiler bug

Chris Torek chris at mimsy.UUCP
Mon Mar 21 17:48:16 AEST 1988


In article <570 at mtxinu.UUCP> tim at mtxinu.UUCP (Tim Wood) writes:
>#define NULL 0
	...
>	unsigned char	**foo;
>
>	foo = NULL;
>	foo = (NULL, NULL);
>	foo = ( !foo ? NULL : (fn(2), NULL) );

[produces]
>"comma.c", line 8: warning: illegal combination of pointer and integer, op =
>"comma.c", line 9: warning: illegal combination of pointer and integer, op =

>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 [0] is assignment
>compatible to all pointers.

I am not convinced it is a bug.  `The integer constant 0' can be
assigned to any pointer; the question is whether the result of a
complex expression can be considered an `integer constant'.

The 11 Jan 1988 draft of the dpANS has this to say about constant
expressions (p. 56):

    CONSTRAINTS
       Constant expressions shall not contain assignment, increment,
    decrement, function-call, or comma operators, except when they are
    contained within the operand of a |sizeof| operator.

That disallows the second expression (foo = (NULL, NULL)) explicitly,
and the third because of the function call; it does not disallow

	foo = 1 ? NULL : NULL;

but the latest pcc seems to allow this anyway.

I do think prohibiting comma expressions in constants is unnecessary.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list