svn commit: r247710 - projects/calloutng/sys/kern
Hans Petter Selasky
hps at bitfrost.no
Tue Mar 5 12:05:47 UTC 2013
On 03/05/13 12:21, Bruce Evans wrote:
> On Tue, 5 Mar 2013, Gleb Smirnoff wrote:
>
>> On Tue, Mar 05, 2013 at 08:43:33PM +1100, Bruce Evans wrote:
>> B> > I think for new code we should prefer C99's bool to boolean_t.
>> B>
>> B> Why? There is no existing practice for this in the kernel. There
>> is some
>> B> in the Linux kernel :-).
>>
>> Why? Because it is standard. What for? To make it more easy for newcomers
>> to start hacking on FreeBSD kernel.
>
> I think you mean "harder". Now the newcomers need to know:
> - the old method, which is used in most places
> - the new method
> - style rules for old, new and mixed methods
> - arcane C99 points like whether bool can be used in bit-fields (I had to
> look this up to check it. It can).
>
> I now see technical reasons to never use bool in kernel or other low-level
> code. It will cause minor pessimizations converting nonzero to true (1)
> at runtime, and for converting bool to register_t when passing parameters
> (bool is 1 byte on x86). To use bool in structs (when not packing it into
> bit-fields), we need to know too much about its size to pack it properly...
>
> Bruce
Hi,
I'm not sure how good you all are at C99. There is a subtle difference
between bool (compiler type) and boolean_t (typedef'ed), and that is
when assigning an non-bool value. This is probably bad style, but I just
want to show you the difference:
#include <stdbool.h>
#include <stdio.h>
typedef int boolean_t;
int main()
{
bool var1;
var1 = 3;
printf("%d\n", var1);
boolean_t var2;
var2 = 3;
printf("%d\n", var2);
return (0);
}
If defined correctly, var1 should contain a value of "1", and var2
should contain a value of "3". Now if for some reason someone like
possibly some Linux guys do, use booleans for counting, you will have an
instant error :-) I'm not saying we should take their example, but
anyhow, be warned about the difference between bool and boolean_t!
--HPS
More information about the svn-src-projects
mailing list