Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: >< swap operator Date: Tue, 02 Oct 2018 10:51:11 -0700 Organization: None to speak of Lines: 29 Message-ID: References: <36d546c5-b471-45fc-b87a-8ebebdc0c0b7@googlegroups.com> <730b028f-e601-4d8b-95ac-1e3c9a11ee89@googlegroups.com> <61b07dd1-2af0-4f82-8ab6-bd831b564c53@googlegroups.com> <8acd77a2-920b-477a-9902-29a555f14440@googlegroups.com> <7dcd73d2-4876-4a78-a1b5-940a0cce5120@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="ab641a093d6af250d7c951df9b0111e8"; logging-data="6224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18D6b6xKopVHmHsUhAa6FeG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:q3zLQvGJ2W83H/uYpwngBAGBD60= sha1:X/9xzsiCnaaNQRDjCZ34Ceejvt0= Xref: csiph.com comp.lang.c:136012 Bart writes: [...] > (If you are using C syntax, then C's comma operator will screw this up: > > a, b, c = 10, 20, 30; > > is legal C, but has the effect of assigning 10 to c, and leaving a and b > unchanged. (This is somewhat surprising, I expected 30 to be assigned to > C.)) It's not surprising if you remember that the comma operator has lower precedence than the assignment operator. You can *very loosely* think of the comma operator as similar to the semicolon, but separating expressions rather than statements. (No need to enumerate the ways in which they differ.) (The idea that an assignment is an expression may seem odd to some.) Of course you can use parentheses: c = (10, 20, 30); which is useful if the operands are expressions with side effects. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"