Path: utzoo!utgpu!water!watmath!clyde!rutgers!labrea!decwrl!hplabs!sdcrdcf!ism780c!nobody From: nobody@ism780c.UUCP (Unprivileged user) Newsgroups: comp.lang.c Subject: Re: comma operator Message-ID: <8599@ism780c.UUCP> Date: 14 Jan 88 22:46:02 GMT References: <3819@sigi.Colorado.EDU> Reply-To: marv@ism780.UUCP (Marvin Rubenstein) Organization: Interactive Systems Corp., Santa Monica CA Lines: 20 In article <3819@sigi.Colorado.EDU> swarbric@tramp.Colorado.EDU (SWARBRICK FRANCIS JOHN) writes: >So, what is >the advantage of using the comma operator other than to squeeze everything >on to one line? At least one use is in a macro, for example: #define foo(a,b) ( (x=(a)+(b)) , (y=(a)-(b) ) If the macro were written as: #define foo(a,b) { (x=(a)+(b)) ; (y=(a)-(b) } then it could only be used in the context of a statement. The first version is an expression so it can be used where a function reference is allowed. The value of the first macro is the value assigned to y (which of course may not be the same as a-b). The second macro has no value. Marv Rubinstein -- Interactive Systems