Path: ...!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!news.gegeweb.eu!gegeweb.org!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail From: Richard Kettlewell Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Thu, 23 May 2024 09:07:23 +0100 Organization: terraraq NNTP server Message-ID: References: <74393ec4-3a71-4b40-b89c-a04c65f92e9e@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6"; logging-data="69949"; mail-complaints-to="usenet@innmantic.terraraq.uk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cancel-Lock: sha1:dviuywF/Qj+diuoQxinUjoFvjOc= X-Face: h[Hh-7npe<v9!1Z&W?r\c.!4DXH5PWpga"ha +r0NzP?vnz:e/knOY)PI- X-Boydie: NO Bytes: 2515 Lines: 31 Malcolm McLean writes: > static int haserror(LEXER *lex) > { > return lex->error[0] ? 1 : 0; > } > > error is a character buffer which holds the error message if an error > has been encountered. And for convenience it is placed in the > lexer. If here is no error, it holds the empty string. However it's > not entirely obvious that testing the message directly is the way you > should be testing for an error condition, so I wrote that little > function to make things clearer. > > It's easy enough to make it return a boolean, of course. But I don't > see a real benefit. Possible benefits: 1) It conveys information to the reader about the nature of the function. In this particular case the name also conveys that information well enough, so there’s not actually much to be gained here, but it other contexts there may be more of an advantage. 2) It conveys information to the compiler that may be exploited by the optimizer (depending on the compilation model, the capabilities of the target platform and optimizer, etc). We are gradually migrating functions with boolean sense to returning bool, albeit not very systematically, mainly for reasons #1. -- https://www.greenend.org.uk/rjk/