Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!amdcad!tim From: tim@amdcad.AMD.COM (Tim Olson) Newsgroups: comp.lang.c Subject: Re: comma operator Message-ID: <19995@amdcad.AMD.COM> Date: 17 Jan 88 21:30:52 GMT References: <3819@sigi.Colorado.EDU> <5080013@hpfcdc.HP.COM> Reply-To: tim@amdcad.UUCP (Tim Olson) Organization: Advanced Micro Devices Lines: 26 In article <5080013@hpfcdc.HP.COM> boemker@hpfcdc.HP.COM (Tim Boemker) writes: | > 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(); | | OK, I'm feeling like a brick... Why can't I write it the | "obvious" way? Because it would expand to if (test(a, b)) {temp=a, a=b, b=temp}; <-- note semicolon else abort(); The semicolon at the end of the swap is a null statement, which makes the 'else' construct illegal, since it doesn't directly follow the statement of the if. -- Tim Olson Advanced Micro Devices (tim@amdcad.amd.com)