Path: utzoo!utgpu!water!watmath!clyde!ima!bbn!bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.lang.c Subject: Re: comma operator Message-ID: <297@fig.bbn.com> Date: 14 Jan 88 05:45:20 GMT References: <3819@sigi.Colorado.EDU> Reply-To: rsalz@fig.bbn.com (Rich Salz) Organization: BBN Laboratories, Cambridge MA Lines: 28 >[what's] the advantage of using the comma operator One use is in when you are only interested in side-effects, followed shortly by a test: for ( ; ; ) { readorexit(); if (satisfied()) break; ... } while (readorexit(), !satisfied()) { ... } Or when you want to tie two actions tightly together: while (argc--, *++argv) ... Perhaps the most common use is when you're writing a macro: #define SWAP(a, b, temp) temp=a, a=b, b=temp You can't write this the "obvious" way: #define SWAP(a, b, temp) {temp=a, a=b, b=temp} because, someone will write if (test(a, b)) SWAP(a, b, temp); else abort(); -- For comp.sources.unix stuff, mail to sources@uunet.uu.net.