Deutsch   English   Français   Italiano  
<wwv34q9q7d0.fsf@LkoBDZeT.terraraq.uk>

View for Bookmarking (what is this?)
Look up another Usenet article

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 <invalid@invalid.invalid>
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: <wwv34q9q7d0.fsf@LkoBDZeT.terraraq.uk>
References: <v2l828$18v7f$1@dont-email.me> <v2lfvr$1ahhf$1@dont-email.me>
	<74393ec4-3a71-4b40-b89c-a04c65f92e9e@gmail.com>
	<v2ll5l$1bg17$1@dont-email.me>
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<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
     F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
     +r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
Bytes: 2515
Lines: 31

Malcolm McLean <malcolm.arthur.mclean@gmail.com> 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/