Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: comma operator: keep away? Message-ID: <10098@smoke.BRL.MIL> Date: 23 Apr 89 00:34:01 GMT References: <19913@iuvax.cs.indiana.edu> <10092@smoke.BRL.MIL> <19926@iuvax.cs.indiana.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 23 In article <19926@iuvax.cs.indiana.edu> bobmon@iuvax.cs.indiana.edu (RAMontante) writes: >I find that neither one uses a comma in getc, getchar, putc, putchar, or >anywhere else, except to separate parameters. Ok, I picked a bad example. However, many macros need to accomplish more than one thing and cannot do so without the aid of some such trickery as ((expr1) & 0 | (expr2)) which is more simply expressed as (expr1, expr2) >Nonetheless I think I get the idea, but that doesn't mean that the code >wouldn't work without the comma (does it?) -- couldn't the same semantics >be reproduced by a series of statements culminating in the final >expression of the parentheses (presumably for assignment purposes)? No! A series of statements cannot be used as a subexpression. Of course -- as I just demonstrated -- there are ways to avoid ever using a comma operator, but then all you really need is a Turing machine, right? So why does C provide more than the logical minimum? It's because it was designed to be USED for real programming, and matters of convenience are quite relevant for that.