Article View: comp.lang.c
Article #1158Re: .5 against 0.5f
From: David Brown
Date: Fri, 30 Oct 2026 08:33
Date: Fri, 30 Oct 2026 08:33
79 lines
5013 bytes
5013 bytes
On 30/10/2026 00:29, Keith Thompson wrote:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>> In article <11bvqbn$3g0tj$1@dont-email.me>,
>> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>>> On 2026-10-28 21: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?
>>>
>>> They can lead to people thinking that return is a function, even if they
>>> nominally know better.
>>
>> What? This is an incredibly weak argument.
>>
>> If someone thought that `return` was a function, then why
>> wouldn't they think that `if` or `while` were also functions?
>> Or `sizeof`, and so on?
>
> I agree that it's a bit of a weak argument, but I wouldn't call it
> incredibly weak.
>
> In my personal coding style, I try to avoid making things that are not
> function calls look like function calls. In a function call, there's no
> space between the function name and the left parenthesis. I don't use
> that style for anything other than function calls (or invocations of
> function-like macros). Not because I don't know return and sizeof are
> keywords, but because it's just a little bit easier to read the code
> if distinctions like that are clear.
>
> Examples:
>
> func(42); // function call, or maybe a macro invocation
> return 42; // not return(42); or even "return (42);
> if (cond) // not if(cond)
> sizeof (int) // not sizeof(int)
> sizeof obj // not sizeof(obj) or sizeof (obj)
>
My preferences are similar, except that rather than distinguishing
between functions and non-functions, I distinguish between statements
and non-statements. So I write "sizeof(int)", rather than having a
space - I see the operator as being more akin to a function call or
macro invocation than to a statement.
(I also write "sizeof(obj)", as that appears more natural to me than
"sizeof obj", and more consistent - I do not like having the parentheses
depend on whether the operand is a type or an expression.)
> The idea is to make the code just a little bit clearer and easier to
> read. If I see something that looks it would be a function call except
> that the prefix is a keyword, it's *very slightly* annoying.
> Parentheses on a return statement are allowed, but they're part of the
> expression, not part of the syntax of the return statement, and they're
> superfluous. I don't write `return (42);` for the same reason I don't
> write `x = (42);`.
When you have a coding style that you have used consistently for a long
time, code written in a different style always looks a bit clumsy and
ugly, and is inevitably at least marginally harder to read. Some people
do put spaces in weird places in their code, such as "if( x ){ ... }",
or they don't use spaces at all, or apparently randomly add long runs of
spaces. There's no accounting for taste!
>
> And of course *all* of these rules can be overridden by a coding
> standard or by the existing style of the surrounding code.
Indeed.
Technical Details
Message-ID:
<11c1kph$31md$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> <868q3hmie0.fsf@linuxsc.com> <11bu8oi$2up7m$1@dont-email.me> <11bvqbn$3g0tj$1@dont-email.me> <11c07vf$lhk$1@reader2.panix.com> <11c0kst$3pmvb$2@kst.eternal-september.org>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: Fri, 30 Oct 2026 09:33:52 +0100 Organization: A noiseless patient Spider Lines: 79 Message-ID: <11c1kph$31md$1@dont-email.me> References: <11bpvs7$1e6kc$2@dont-email.me> <868q3hmie0.fsf@linuxsc.com> <11bu8oi$2up7m$1@dont-email.me> <11bvqbn$3g0tj$1@dont-email.me> <11c07vf$lhk$1@reader2.panix.com> <11c0kst$3pmvb$2@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 30 Oct 2026 08:33:53 +0000 (UTC) Injection-Info: dont-email.me; logging-data="100045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QyM8pbSUJ2676puLYJ3U62Div7RbYWXM="; posting-host="005feb7eca873ed1ea966324157898e1" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:6KD7cWWRH21gWGElz+Hg8mZCeP4= sha256:BjFRroFB+1zDXQsraBTbsBnyjJ1ERmBQiqFgIv0gL8I= sha1:X1caMImZ2JK8B/kMUI9QvpgBN7I= sha256:TQKYqe0FM1hzLoKTb31u0wG66eatazqm+vvC2OpXfWA= In-Reply-To: <11c0kst$3pmvb$2@kst.eternal-september.org> Content-Language: en-GB, nb-NO