Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: How About Disallowing Assignments In Expressions? Date: Wed, 14 Feb 2024 22:07:03 -0800 Organization: A noiseless patient Spider Lines: 42 Message-ID: <86bk8i1cs8.fsf@linuxsc.com> References: <87r0hlef8q.fsf@nosuchdomain.example.com> <87sf20o4e2.fsf@bsb.me.uk> <87a5o3amit.fsf@nosuchdomain.example.com> <20240214120232.00001d56@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="d6a0776853173adee93a90f6ecdad10b"; logging-data="3342924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19R7DA6i18wpoA9kKizNRbEAGeFT8SRSg0=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:DfFr2E0XVr5wA4iBDV/kW5qpNvw= sha1:lITtGxLuok4VIAI7N1mFA/TQ004= Xref: csiph.com comp.lang.c:382506 scott@slp53.sl.home (Scott Lurndal) writes: > Michael S writes: > >> On Tue, 13 Feb 2024 16:59:38 -0800 >> Keith Thompson wrote: >> > >>> >>> Though personally, I'd probably make the assignment the operand of a >>> larger expression. I understand that >>> if (foo) >>> is a common idiom where foo is of any scalar type, but I personally >>> prefer to write one of >>> if (foo != 0) >>> if (foo != '\0') >>> if (foo != 0.0) >>> if (foo != NULL) >>> because I find it clearer (unless foo is of type bool or is otherwise >>> appropriate to use directly as a condition). >>> >>> Thus if x and y are ints, I'd probably write: >>> if ((x = y) != 0) >>> (Assuming I'm not required to follow MISRA rules.) >>> >>> YMMV. >> >> Agreed with two small exception: >> (1) I never write '\0' myself always preferring plain 0. > > I'm in Keith's camp here when working with a char type, I'll > use '\0' rather than plain zero. > > I tend to suffix constants as well if they're not being > used as 'int', perhaps a bit too picky? > > uint64_t v; > ... > if (v == 0ul) ... You say what you do but don't say why. Can you explain your rationale or motivation?