Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Range-aware modulo operator -% Date: Tue, 01 Jan 2019 17:53:18 -0800 Organization: None to speak of Lines: 42 Message-ID: References: <9RxWD.81420$N45.2557@fx21.am4> <65TWD.67453$Ab5.11301@fx04.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="4d2fb03eb8a6f1b5fb918b8f9f106071"; logging-data="2657"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tAhi9xwMCW13iqfyw/8CV" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:RowciJAwxzXwH9nvcX2Idd62pGE= sha1:wQrK3+C+EvQRgH4lU5+dhlWHscc= Xref: csiph.com comp.lang.c:139350 Bart writes: > On 02/01/2019 00:09, Keith Thompson wrote: [...] >> But I'm curious, do you understand the description in the standard? >> Did you even know what it said before I pointed it out? > > You mean 6.8.4.1p2? No I don't remember looking at it before. So you've been describing how conditions work in C without knowing what the standard says about them. > I don't think such expressions in C are much different from many other > languages, and I've implemented this too many times to be in need of > such guidance. > > The text talks about comparing the expression with 0, which is fine for > a programmer, but an implementer (this one, anyway) prefers it pinned > down a little more. The description in the standard tells you everything you need to know to implement it, if you're willing to think about it a little. > Since an equality comparison with 0 might need to take account of > multiple widths, and several types (int, pointer, float). A pseudo-bool > result is just one type, not even a width when there is no actual bool type. A comparison with 0 may require a type conversion, as clearly described by the C standard. > (Also, with certain languages I implement, [snip] We were talking about C. Of course if you're implementing something other than C, you should follow the rules of that language. [...] -- Keith Thompson (The_Other_Keith) kst@mib.org Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"