[pisa-src] Re: r2518 - in trunk/tools/dhcp: mac2ip.c mac2ip.h

  • From: Christoph Viethen <christoph.viethen@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 05 Apr 2011 16:18:32 +0200

Hello,

On Apr 5, 2011, at 3:07 PM, Christof Mroz wrote:

>> +struct ip_bound {
>> +    mac2ip_ipv4_t bound;
>> +    _Bool         valid;
>> +};
>> +
> 
> Could the standard bool type from <stdbool.h> be used here?

Well, here's my problem:

"_Bool" *is* the standard boolean type ... according to the C99 standard. I've 
got no idea how they arrived at that conclusion, but to me it seemed that, as 
ugly and weird as it may look, "_Bool" would be the most portable and correct 
approach. At least in an ideal C99 world, using "_Bool" should force the 
compiler to provide a type that can only be 0 or 1 and nothing else, whereas my 
fear was that using "bool" may get us a type that behaves like an integer. (All 
this does make me cringe quite a bit!)

On the other hand, I just looked into ISO9945, and they say:

bool        Expands to _Bool

So one might argue that if one follows POSIX.1-2008 as well as C99, "bool" is 
just as good as "_Bool" (and doesn't look half as scary). Hmmm.

I guess it's a bit of a policy question: always use standard types, or make a 
special exception for better readability here?


By the way, is there a way to make GCC issue a warning if somebody tries to 
assign, to a variable of type _Bool, a value larger 1 or smaller than 0 ? I'm 
aware that such assignment is permitted by the standard: if one assigns to a 
_Bool a value of 0, it will be 0, if one assigns a value != 0, it will always 
be as if one had assigned 1. Still, I'm wondering whether it wouldn't make 
sense for a compiler to issue a warning in such cases, because this way one 
might enforce a cleaner programming style (and catch bugs, potentially).


>> +    struct ip_bound lower_client;
>> +    struct ip_bound upper_client;
>> +    struct ip_bound lower_service;
>> +    struct ip_bound upper_service;
>> } ip_bounds;
>> /*
> 
> Would it make sense to declare struct ip_range, to reduce clutter even more?

You got a point there ... let's see to that later. I've got a few more bug 
fixes in the pipeline first. Also, I have the suspicion that the whole "get 
those values from a config file of their own" business is something that I 
might be able to get rid of entirely, so it might not be necessary to optimize 
it further.


Cheers,

  Christoph

-- 
 christoph.viethen@xxxxxxxxxxxxxx

-- 
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts: