Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.lang.c Subject: Re: comma operator Message-ID: <4006@june.cs.washington.edu> Date: 18 Jan 88 21:19:57 GMT References: <3819@sigi.Colorado.EDU> <8599@ism780c.UUCP> <1866@bsu-cs.UUCP> Reply-To: pardo@uw-june.UUCP (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 22 [ Don't use comma op because it may not be very well tested ] [ Go ahead and use it -- it will work ] The comma operator is guaranteed (K&R pg. 192, sect 7.15) to evaluate left to right and return the value of the right operand. Most of the time that the comma operator is used, neither the order or the return value is used, but because of the C guarantee, compiler optimizations may be wasted. On the other hand, in most of the situations where the comma operator is used, there is no alternative legal C for the code, so we ignore the lost optimization. Simply using the comma opeator, however, to group related code may result in slower code. I therefore _suggest_ that using the comma operator only where necessary is a good idea if you are writing time-critical code. Gee, wouldn't it be nice if we could do: for ({i = 0; sum = 0;}; i < limit; ++i) sum += a[i]; ;-D on (I was an undercover operator in the ...) Pardo