Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Comma operator in for() statements Date: Fri, 27 Mar 2020 07:42:00 -0700 Organization: A noiseless patient Spider Lines: 63 Message-ID: <86r1xd97wn.fsf@linuxsc.com> References: <1NIdG.90366$0hk.19720@fx08.am4> <0fc029c2-7036-4ca9-86af-15913f874a08@googlegroups.com> <20200324202535.68c64bb9be8f95153b947f4b@g{oogle}mail.com> <878sjp1gk1.fsf@bsb.me.uk> <20200325145934.5f39e56fc029b19da139cc0d@g{oogle}mail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="02cbe0882c270f81c5b8b4aa13e82222"; logging-data="10934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187R5CPgOhGNTKp9U+zBVQWfX7eKgXjhdc=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:qMjlrDPB96nDzVlH2jt9OSwf1YI= sha1:Nsazwohtmg3ujc4+g9tA3PGxPeg= Xref: csiph.com comp.lang.c:150859 Anton Shepelev writes: > Ben Bacarisse to Anton Shepelev: > >>> My negative criticism of C's `for' statement is that it >>> is essentialy a rather complicated *functional* >>> statement, because it comprises four pieces of code that >>> are executed in a non-trivial order and with non-trivial >>> relations. Passing pieces of code to statements is >>> functional programming. In procedural programming, one >>> passes data, that is, in our case, -- index boundaries. >> >> What about the body? > > Indeed. I was wrong, and should have named three instead of > four functional pieces of code. > >> What about the condition in an 'if' and the arms of an >> 'if'. > > The codition of an `if' is not a piece of code passed to a > statement because it is executed only once, and can be > replaced by its pre-calculated truth value, taking into > account short-circuit evaluation and C's vague separation > between statements and expressions. > > The body (or bodies) of control statmenets are not, in my > view, passed to statements at all. Rather, the control-flow > statements are mark-up around blocks of linear (non-control) > code. Operator braces {} are just mark up. > >> The condition and body of a while? > > Yes, `while' "takes" the loop invariant in the same sense as > does `for', yet `while' is much simpler and much more > intutive in that it "takes" only one piece of code, which > can be kept strictly as control code (only checks, no > assignments), and that it is executed in the intuitive order > of appearance. The same applies to do..while. > > One of the worst abuses of `while' is code for which many > programmers praise C: > > char *s, *d; > /* ... */ > while (*d++ = *s++); > > It employs several means of obfuscation: > > 1. loop-control statements with side effects, > > 2. use of counter-intuitive post-increment operator on > both parts of an assibnment. > > 3. confusion of logical condition and comparison with > zero. > > 4. an empty body of the `while' statement. It's idiomatic C. Perhaps more importantly, C not only allows such constructions but embraces them stylistically. Such things have been part of C since its earliest beginnings. If someone wants to write Pascal-style code they should write in Pascal.