Article View: comp.lang.c
Article #1104Re: .5 against 0.5f
From: David Brown
Date: Thu, 29 Oct 2026 09:45
Date: Thu, 29 Oct 2026 09:45
79 lines
5074 bytes
5074 bytes
On 29/10/2026 02:50, Steven G. Kargl wrote: > On Wed, 28 Oct 2026 17:59:19 -0700, Tim Rentsch wrote: > >> "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> writes: >> >>> On Wed, 28 Oct 2026 16:39:00 -0700, Keith Thompson wrote: >>> >>>> (Also, you misspelled "ROFL", and you don't need parentheses on the >>>> return statement, particularly if you dislike fluff.) >>> >>> Yeah, I was laugh too hard while typing ;-) >>> >>> Parentheses is a habit from BSD kernel source file style guide. >> >> Now is a good time to start unlearning that habit. > > Why? What harm do the parentheses cause? I can't see that parentheses here cause any actual harm - but they are certainly unnecessary fluff, and do no good. Every extra level of parentheses adds to the cognitive effort required to understand and interpret an expression. It takes longer to read, and has a higher chance of misinterpretation. If the parenthesis are necessary - "(a + b) * c" - then this is clearly a cost worth paying. Sometimes parentheses are not necessary, but /reduce/ the cognitive effort, such as "(a > 2) && (a < 5)". Again, the parentheses are then a good thing (albeit subjectively). But in "return (x);", they add nothing but cognitive effort. The C programmer's brain has to consider and reject the possibility that this is a function call or a macro invocation. The effort is small, but nonetheless wasted. Let me put it another way. What benefit do you think there is from these parentheses? Why does the FreeBSD style guide recommend them? I can see benefits in consistency of style once that usage has been established, but why have them in the first place? > > Unlearning is not likely to happen. I've been a long-time > contributor to FreeBSD, and have no plans to stop. Feel > free to check the git history on FreeBSD libm sources. > My finger prints are all over the code. So, yeah, I know > a enough about floating point arithmetic and C standard > requirements to be dangerous. > >>> % man 9 style >>> ... >>> >>> Values in return statements should be enclosed in parentheses. >>> >>> >>> I also have debugging macros RETURNI() that require parens. >> >> That strengthens the motivation not to use parentheses with >> return statements, to emphasize that they are different from >> the macros. > > Do you ignore the style requirements of all the projects > that you may have worked on, and simply use whatever > your personal preferences are? > When working on code with particular style requirements, it makes sense to follow those style requirements - even if you disagree with the requirements. When working on other code, you are then freed from following rules that are unnecessary or counter-productive. If I were contributing code to FreeBSD and it /requires/ parentheses in return statements for the code to be accepted, I'd put parentheses in return statements. If it merely /recommends/ them, I would not do so - but would change my mind if other FreeBSD contributors made a fuss about it. In no other code would I use them, and in code reviews I would ask for them to be removed. But I would not bother about them in throw-away Usenet code, except if the post was complaining about other unnecessary "fluff" :-)
Technical Details
Message-ID:
<11bv4jd$37ch9$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@dont-email.me> <11br792$1u7e5$1@dont-email.me> <11brgqf$21170$2@dont-email.me> <11brkco$21oj5$1@dont-email.me> <11bs4tj$26daj$1@dont-email.me> <11bs613$26knh$1@dont-email.me> <11bt7ff$2i0ag$1@dont-email.me> <11btm2a$2ojn1$2@kst.eternal-september.org> <11bttrp$2qvg6$1@dont-email.me> <11bu12l$2rgo2$4@kst.eternal-september.org> <11bu3kk$2svh8$1@dont-email.me> <868q3hmie0.fsf@linuxsc.com> <11bu8oi$2up7m$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Thu, 29 Oct 2026 10:45:16 +0100 Organization: A noiseless patient Spider Lines: 79 Message-ID: <11bv4jd$37ch9$1@dont-email.me> References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@dont-email.me> <11br792$1u7e5$1@dont-email.me> <11brgqf$21170$2@dont-email.me> <11brkco$21oj5$1@dont-email.me> <11bs4tj$26daj$1@dont-email.me> <11bs613$26knh$1@dont-email.me> <11bt7ff$2i0ag$1@dont-email.me> <11btm2a$2ojn1$2@kst.eternal-september.org> <11bttrp$2qvg6$1@dont-email.me> <11bu12l$2rgo2$4@kst.eternal-september.org> <11bu3kk$2svh8$1@dont-email.me> <868q3hmie0.fsf@linuxsc.com> <11bu8oi$2up7m$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 29 Oct 2026 09:45:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3387945"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6N/0RecH/z7GZHy1B4ZLIoMUTIJXpzho="; posting-host="ee186c62f9168531a82b8aa89ffdfee0" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:KboWEJ60K10iTBywuSrBesaFJm0= sha256:UJeOL8H68KQVLcIYbTr0LCsQfl+XF9H0LYhdTeVnzzo= sha1:djHlExEyBcG8Jz31V8iyLdHSSnU= sha256:RNbmaZCyTztADYiOVT7VKi/CQ9q3YJM00G305e9dhmQ= In-Reply-To: <11bu8oi$2up7m$1@dont-email.me> Content-Language: en-GB, nb-NO