2006-08-01 19:20:40

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

[email protected] wrote:
> This patch defines:
> * a generic boolean-type, named "bool"
> * aliases to 0 and 1, named "false" and "true"
>
> Signed-off-by: Richard Knutsson <[email protected]>

Shouldn't this simply use _Bool?

-hpa


2006-08-01 21:13:27

by Richard Knutsson

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

Citerar "H. Peter Anvin" <[email protected]>:

> [email protected] wrote:
> > This patch defines:
> > * a generic boolean-type, named "bool"
> > * aliases to 0 and 1, named "false" and "true"
> >
> > Signed-off-by: Richard Knutsson <[email protected]>
>
> Shouldn't this simply use _Bool?

Well, it is (now) just a typedef of it. :)

But I find it better, both because it is more similar to the common types:
short, lowlettered words. But also because most editors with highlightning
recognize "bool", but not "_Bool", as a type (as I found it).

> -hpa

/Richard Knutsson

2006-08-01 21:21:31

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

[email protected] wrote:
> Citerar "H. Peter Anvin" <[email protected]>:
>
>> [email protected] wrote:
>>> This patch defines:
>>> * a generic boolean-type, named "bool"
>>> * aliases to 0 and 1, named "false" and "true"
>>>
>>> Signed-off-by: Richard Knutsson <[email protected]>
>> Shouldn't this simply use _Bool?
>
> Well, it is (now) just a typedef of it. :)
>
> But I find it better, both because it is more similar to the common types:
> short, lowlettered words. But also because most editors with highlightning
> recognize "bool", but not "_Bool", as a type (as I found it).
>

<stdbool.h> should include:

typedef _Bool bool;
#define true 1
#define false 0

There is no enum involved.

-hpa

2006-08-01 21:24:11

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

H. Peter Anvin wrote:
> [email protected] wrote:
>> This patch defines:
>> * a generic boolean-type, named "bool"
>> * aliases to 0 and 1, named "false" and "true"
>>
>> Signed-off-by: Richard Knutsson <[email protected]>
>
> Shouldn't this simply use _Bool?

No sane person should use "_Bool" in real code. Unnecessary StudlyCaps
and unnecessary underscore.

"bool" is far easier to type, and looks less weird.

Jeff



2006-08-01 21:31:42

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

H. Peter Anvin wrote:
> There is no enum involved.

There should be. It makes more information available to the C compiler,
and it makes useful symbols available to the debugger.

Jeff


2006-08-01 21:42:36

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

Jeff Garzik wrote:
> H. Peter Anvin wrote:
>> [email protected] wrote:
>>> This patch defines:
>>> * a generic boolean-type, named "bool"
>>> * aliases to 0 and 1, named "false" and "true"
>>>
>>> Signed-off-by: Richard Knutsson <[email protected]>
>>
>> Shouldn't this simply use _Bool?
>
> No sane person should use "_Bool" in real code. Unnecessary StudlyCaps
> and unnecessary underscore.
>
> "bool" is far easier to type, and looks less weird.
>

That wasn't the point. The point was that bool should be a typedef to
_Bool instead of an enum.

-hpa

2006-08-01 21:43:11

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

Jeff Garzik wrote:
> H. Peter Anvin wrote:
>> There is no enum involved.
>
> There should be. It makes more information available to the C compiler,
> and it makes useful symbols available to the debugger.
>

_Bool is a native C type; it has all the information the C compiler needs.

-hpa

2006-08-01 21:47:25

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

H. Peter Anvin wrote:
> That wasn't the point. The point was that bool should be a typedef to
> _Bool instead of an enum.

Quoting from the patch to which you are replying:

+typedef _Bool bool;

'enum' is only used for defining 'true' and 'false'.

Jeff


2006-08-01 21:48:18

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

H. Peter Anvin wrote:
> Jeff Garzik wrote:
>> H. Peter Anvin wrote:
>>> There is no enum involved.

>> There should be. It makes more information available to the C
>> compiler, and it makes useful symbols available to the debugger.

> _Bool is a native C type; it has all the information the C compiler needs.

"#define true 1" however does not.

Jeff



2006-08-01 21:54:55

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 1/2] include/linux: Defining bool, false and true

Jeff Garzik wrote:
> H. Peter Anvin wrote:
>> Jeff Garzik wrote:
>>> H. Peter Anvin wrote:
>>>> There is no enum involved.
>
>>> There should be. It makes more information available to the C
>>> compiler, and it makes useful symbols available to the debugger.
>
>> _Bool is a native C type; it has all the information the C compiler
>> needs.
>
> "#define true 1" however does not.
>

I guess that's fair, although when you put it into a type _Bool they're
going to devolve to pure constants.

-hpa