Path: utzoo!utgpu!water!watmath!clyde!rutgers!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: <4018@june.cs.washington.edu> Date: 20 Jan 88 06:55:59 GMT References: <3819@sigi.Colorado.EDU> <8599@ism780c.UUCP> <1866@bsu-cs.UUCP> <4006@june.cs.washington.edu> <3586@sdcc6.ucsd.EDU> Reply-To: pardo@uw-june.UUCP (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 25 [ how could the comma operator cause slower code? ] Because the comma operator guarantees an order of evaluation on two statements that the compiler might otherwise rearrange to produce more efficient code. As a brain-dead example: ++x, ++y; if (x % n) { ... } If the comma was replaced by a semicolon, the compiler could rewrite it as ++y; if (++x % n) { ... } Which would be faster on many machines. I'm not saying that this happens all the time or that you should worry about it in the normal case, but if you are writing code where you need all the optimization you can get (particularly if your compiler does good code-motion) then you might want to worry that the compiler can't optimize that extra cycle (because the comma operator guarantees order of execution). ;-D on (speed, like cocaine, is highly illegal) Pardo