Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news.unit0.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Wed, 07 Jun 2017 14:54:26 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: memscan() function or equivalent References: <20170607154705.f161b2807eb2b1a8dc12d389@gmail.com> <12fb0e96-0ac3-442d-8d04-baaef4234a85@googlegroups.com> <20170607164800.a6fba9d07170ec5d056d25a0@gmail.com> <878tl3g5jw.fsf@bsb.me.uk> Date: Wed, 07 Jun 2017 20:54:25 +0100 Message-ID: <87wp8n4lqm.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:e+ETer3N7z/SoeCP2nPxtbsReC4= MIME-Version: 1.0 Content-Type: text/plain Lines: 38 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-EOtAlCS7PIc1ZWkCvGfnlekHwQKE0jusTKn16mobN014v9NqWHV4kL1tuCT7USzLuBsu6MYOVsUYKVD!+7ymCJ2tM4rvqrIFtzjupFyfnvD4xcXNujuxdmpiRHYqY6nvPrAyn7McyxlqmFsAVETRqmA= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2257 Xref: csiph.com comp.lang.c:111749 Ben Bacarisse writes: > What is the general view of writing things like > > k += *s0 == c0; > > ? I find it compact and natural with no extra cost, at least with > modern compilers. I don't madly care for it. My brain has to work to spot which is the assignment, and which is the comparison. I'd probably write if(*s0 == c0) k = k+1; That's comprehensible to any programmer anywhere, and idiomatic in almost every major imperative language - as well as directly expressing what you want to do Which of these is clearest: "If the characters match, increment the counter". "Increment the counter by one if the characters match, or zero if they don't" They're logically equivalent identical, but one of those reads like I think, and one of them reads like it was written by a Cylon. I'd also consider k += (*s0 == c0); preferable to yours. I find it simply easier to parse mentally without back-tracking. Any compiler that produces different code for these should be taken out and shot.