[comp.arch] the comma operator and other comments

kruger@16bits.dec.com (Hart for CCCP chief in '88) (01/15/88)

>	int	a, *b, *c[], d ;
> 
>	d = a ** d ;
>	d = a ***b ;		/* is (a ** (*b)) */
>	d = *b****c ;		/* although hard to see ((*b) ** (*(*c))) */

Syntactically horrendous. Why add more weirdness? C has enough already.

Frank Swarbrick writes about the comma ....

>generated the same exact code, though I was too lazy to check.  So, what is
>the advantage of using the comma operator other than to squeeze everything
>on to one line?

The comma is a sequence point. All side effects must take place by the comma.
For example:

	*x++ + *x++

is bad programming style whose behavior is NOT defined by the standard. It
could be treated, for example, as:

	MOV (x)+,temp
	ADD (x)+,temp

or as
	mov (x),temp
	add (x),temp
	add #4,x

assuming a pointer to int. We chose the first way for the PDP-11 C project,
which happens to be the "natural" thing to do, what the programmer is expecting.
For long-ints though, we were forced to take the second road. Ugly, but
necessary.
All that ANSI guarantees is that the side effects will be done on or before the
next "sequence point." The semicolon and comma are sequence points.

dov