Sujet : Re: C23 thoughts and opinions
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.cDate : 22. May 2024, 21:39:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2ll5l$1bg17$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 22/05/2024 20:40, Thiago Adams wrote:
On 22/05/2024 16:10, Malcolm McLean wrote:
And why do you really need a boolean when an int can hold either a zero or non-zero value?
What do you use instead? A typedef?
Here's a code snippet I wrote today.
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.
-- Check out Basic Algorithms and my other books:https://www.lulu.com/spotlight/bgy1mm