Re: Against bool

Liste des GroupesRevenir à l c 
Sujet : Re: Against bool
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.c
Date : 31. May 2024, 07:49:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3bodm$23sno$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 31/05/2024 04:22, Lawrence D'Oliveiro wrote:
On Thu, 30 May 2024 17:16:40 +0100, Malcolm McLean wrote:
 
And so we want to abolish bool and replace it with a bool enum.
      bool is_array(XMLNODE * node, bool useattributes);
     bool is_object(XMLNODE * node, bool useattributes);
     bool is_field(XMLNODE * node, bool useattributes);
 Seems to me, the use of “bool” helps make pretty clear what those
arguments are for. What’s wrong with that?
if (is_array(node))
{
    /* node is an array, output jSON array */
}
very obvious. And bool make no difference. And isspace() returns an integer in standard C. The convention is that 0 = false, and non zero =
true. So comparing the result to 1 or to "true" is an error.
if (isarray(node, useattributes))
ok, not entirely obvious, but in fact whether a node should be a JSON array or not depends on whether the user wants to consider XML attributes or ignore them, and most pepole will get the idea.
if (is_array(node, true))
Now what the hell?
if (is_array(node, YES_USEATTRIBUTES))
Now were getting somewhere.
However if we do
#define YES_USE_ATTRIBUTES true
or some equivalent, then peple can just pass "true" and defeat the system.
So this is cuter
#define NO_USEATTRIBUTES 0
#define YES_USEATRRIBUTES 12345
int is_array(XML node *node, int useatrributes)
{
    assert(useattributes == NO_USEATTRIBUTES|| useattributes == YES_USEATTRIBUTES);
}
And now we're maybe tightening things up a bit.
But we need bool enums. If we are to have boolean types in C, they need to be done properly. Just defining sysmbols for true and false isn't adequate. Anyone can do that in two minutes.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Date Sujet#  Auteur
30 May 24 * Against bool7Malcolm McLean
31 May 24 +* Re: Against bool3Lawrence D'Oliveiro
31 May 24 i`* Re: Against bool2Malcolm McLean
31 May 24 i `- Re: Against bool1Lawrence D'Oliveiro
31 May 24 +- Re: Against bool1Blue-Maned_Hawk
31 May 24 +- Re: Against bool1David Brown
31 May 24 `- Re: Against bool1Thiago Adams

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal