linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] A generic boolean-type
@ 2006-07-29 12:19 ricknu-0
  2006-07-29 12:32 ` [PATCH 1/2] include/linux: Defining bool, false and true ricknu-0
  2006-07-29 12:36 ` [PATCH 2/2] drivers: Removes colliding boolean definitions ricknu-0
  0 siblings, 2 replies; 13+ messages in thread
From: ricknu-0 @ 2006-07-29 12:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeff Garzik, Alexey Dobriyan, Vadim Lobanov,
	Jan Engelhardt, Shorty Porty, Peter Williams, Michael Buesch,
	Pekka Enberg, Stefan Richter, larsbj, Michael Buesch,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

Hi

Here is the first "real" patch to make a generic boolean-type.
Andrew, would you please pick this one up?

First patch:
The boolean is named "bool", this because calling it "boolean" seems long (int
and integer) and not "BOOL", because it is a typedef and not a #define.


The patch also defines aliases to 0 and 1, called "false" and "true".
There has been some who do not want the true and false, but since it is just a
value and not bundled with the boolean type, it is up to the programmer which to
use. Also a quick check:

find . -name *.[chS] | xargs grep "define FALSE" | grep -v "FALSE_" | wc -l
55

tells us there seems to be some who like false and true (and a need for a common
definition, as Andrew attemted).


Secound patch:
Just a "cleanup" of files with common definitions of bool/false/true.


These patches has been applied on the current Linus git-tree and compile-tested.

Hopefully, this patch will be picked up by someone and then the real work can
start, converting those files who uses booleans (and/or false/true). This would
most likely occure at kernel-janitors.

Till next time
/Richard Knutsson

PS
If you do not want to be CC'ed, please tell and I will remove your address.
DS


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] include/linux: Defining bool, false and true
  2006-07-29 12:19 [PATCH 0/2] A generic boolean-type ricknu-0
@ 2006-07-29 12:32 ` ricknu-0
  2006-08-01 19:19   ` H. Peter Anvin
  2006-07-29 12:36 ` [PATCH 2/2] drivers: Removes colliding boolean definitions ricknu-0
  1 sibling, 1 reply; 13+ messages in thread
From: ricknu-0 @ 2006-07-29 12:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeff Garzik, Alexey Dobriyan, Vadim Lobanov,
	Jan Engelhardt, Shorty Porty, Peter Williams, Michael Buesch,
	Pekka Enberg, Stefan Richter, larsbj, Paul Jackson, Josef Sipek,
	Arnd Bergmann, Nicholas Miell, Alan Cox, Lars Noschinski

This patch defines:
* a generic boolean-type, named "bool"
* aliases to 0 and 1, named "false" and "true"

Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>

---

 stddef.h |    5 +++++
 types.h  |    2 ++
 2 files changed, 7 insertions(+)


diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index b3a2cad..0382065 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -10,6 +10,11 @@ #else
 #define NULL ((void *)0)
 #endif
 
+enum {
+	false	= 0,
+	true	= 1
+};
+
 #undef offsetof
 #ifdef __compiler_offsetof
 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
diff --git a/include/linux/types.h b/include/linux/types.h
index 3f23566..406d4ae 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -33,6 +33,8 @@ typedef __kernel_clockid_t	clockid_t;
 typedef __kernel_mqd_t		mqd_t;
 
 #ifdef __KERNEL__
+typedef _Bool			bool;
+
 typedef __kernel_uid32_t	uid_t;
 typedef __kernel_gid32_t	gid_t;
 typedef __kernel_uid16_t        uid16_t;


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] drivers: Removes colliding boolean definitions
  2006-07-29 12:19 [PATCH 0/2] A generic boolean-type ricknu-0
  2006-07-29 12:32 ` [PATCH 1/2] include/linux: Defining bool, false and true ricknu-0
@ 2006-07-29 12:36 ` ricknu-0
  1 sibling, 0 replies; 13+ messages in thread
From: ricknu-0 @ 2006-07-29 12:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeff Garzik, Alexey Dobriyan, Vadim Lobanov,
	Jan Engelhardt, Shorty Porty, Peter Williams, Michael Buesch,
	Pekka Enberg, Stefan Richter, larsbj, Paul Jackson, Josef Sipek,
	Arnd Bergmann, Nicholas Miell, Alan Cox, Lars Noschinski

Removing definitions of bool, false and true, preventing collisions with the
generic definition.

Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>

---

 block/DAC960.h            |    2 +-
 media/video/cpia2/cpia2.h |    4 ----
 net/dgrs.c                |    1 -
 scsi/BusLogic.h           |    5 +----
 4 files changed, 2 insertions(+), 10 deletions(-)


diff --git a/drivers/block/DAC960.h b/drivers/block/DAC960.h
index a82f37f..f9217c3 100644
--- a/drivers/block/DAC960.h
+++ b/drivers/block/DAC960.h
@@ -71,7 +71,7 @@ #define DAC690_V2_PciDmaMask	0xfffffffff
   Define a Boolean data type.
 */
 
-typedef enum { false, true } __attribute__ ((packed)) boolean;
+typedef bool boolean;
 
 
 /*
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index c5ecb2b..8d2dfc1 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -50,10 +50,6 @@ #define CPIA2_PATCH_VER	0
 /***
  * Image defines
  ***/
-#ifndef true
-#define true 1
-#define false 0
-#endif
 
 /*  Misc constants */
 #define ALLOW_CORRUPT 0		/* Causes collater to discard checksum */
diff --git a/drivers/net/dgrs.c b/drivers/net/dgrs.c
index fa4f094..4dbc23d 100644
--- a/drivers/net/dgrs.c
+++ b/drivers/net/dgrs.c
@@ -110,7 +110,6 @@ static char version[] __initdata =
  *	DGRS include files
  */
 typedef unsigned char uchar;
-typedef unsigned int bool;
 #define vol volatile
 
 #include "dgrs.h"
diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h
index 9792e5a..d6d1d56 100644
--- a/drivers/scsi/BusLogic.h
+++ b/drivers/scsi/BusLogic.h
@@ -237,10 +237,7 @@ enum BusLogic_BIOS_DiskGeometryTranslati
   Define a Boolean data type.
 */
 
-typedef enum {
-	false,
-	true
-} PACKED boolean;
+typedef bool boolean;
 
 /*
   Define a 10^18 Statistics Byte Counter data type.


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-07-29 12:32 ` [PATCH 1/2] include/linux: Defining bool, false and true ricknu-0
@ 2006-08-01 19:19   ` H. Peter Anvin
  2006-08-01 21:12     ` ricknu-0
  2006-08-01 21:23     ` Jeff Garzik
  0 siblings, 2 replies; 13+ messages in thread
From: H. Peter Anvin @ 2006-08-01 19:19 UTC (permalink / raw)
  To: ricknu-0
  Cc: linux-kernel, Andrew Morton, Jeff Garzik, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

ricknu-0@student.ltu.se wrote:
> This patch defines:
> * a generic boolean-type, named "bool"
> * aliases to 0 and 1, named "false" and "true"
> 
> Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>

Shouldn't this simply use _Bool?

	-hpa

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 19:19   ` H. Peter Anvin
@ 2006-08-01 21:12     ` ricknu-0
  2006-08-01 21:20       ` H. Peter Anvin
  2006-08-01 21:23     ` Jeff Garzik
  1 sibling, 1 reply; 13+ messages in thread
From: ricknu-0 @ 2006-08-01 21:12 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: linux-kernel, Andrew Morton, Jeff Garzik, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

Citerar "H. Peter Anvin" <hpa@zytor.com>:

> ricknu-0@student.ltu.se wrote:
> > This patch defines:
> > * a generic boolean-type, named "bool"
> > * aliases to 0 and 1, named "false" and "true"
> > 
> > Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>
> 
> 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:12     ` ricknu-0
@ 2006-08-01 21:20       ` H. Peter Anvin
  2006-08-01 21:31         ` Jeff Garzik
  0 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2006-08-01 21:20 UTC (permalink / raw)
  To: ricknu-0
  Cc: linux-kernel, Andrew Morton, Jeff Garzik, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

ricknu-0@student.ltu.se wrote:
> Citerar "H. Peter Anvin" <hpa@zytor.com>:
> 
>> ricknu-0@student.ltu.se wrote:
>>> This patch defines:
>>> * a generic boolean-type, named "bool"
>>> * aliases to 0 and 1, named "false" and "true"
>>>
>>> Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>
>> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 19:19   ` H. Peter Anvin
  2006-08-01 21:12     ` ricknu-0
@ 2006-08-01 21:23     ` Jeff Garzik
  2006-08-01 21:41       ` H. Peter Anvin
  1 sibling, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2006-08-01 21:23 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

H. Peter Anvin wrote:
> ricknu-0@student.ltu.se wrote:
>> This patch defines:
>> * a generic boolean-type, named "bool"
>> * aliases to 0 and 1, named "false" and "true"
>>
>> Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>
> 
> 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




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:20       ` H. Peter Anvin
@ 2006-08-01 21:31         ` Jeff Garzik
  2006-08-01 21:42           ` H. Peter Anvin
  0 siblings, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2006-08-01 21:31 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

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



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:23     ` Jeff Garzik
@ 2006-08-01 21:41       ` H. Peter Anvin
  2006-08-01 21:47         ` Jeff Garzik
  0 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2006-08-01 21:41 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

Jeff Garzik wrote:
> H. Peter Anvin wrote:
>> ricknu-0@student.ltu.se wrote:
>>> This patch defines:
>>> * a generic boolean-type, named "bool"
>>> * aliases to 0 and 1, named "false" and "true"
>>>
>>> Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>
>>
>> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:31         ` Jeff Garzik
@ 2006-08-01 21:42           ` H. Peter Anvin
  2006-08-01 21:48             ` Jeff Garzik
  0 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2006-08-01 21:42 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:41       ` H. Peter Anvin
@ 2006-08-01 21:47         ` Jeff Garzik
  0 siblings, 0 replies; 13+ messages in thread
From: Jeff Garzik @ 2006-08-01 21:47 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

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



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:42           ` H. Peter Anvin
@ 2006-08-01 21:48             ` Jeff Garzik
  2006-08-01 21:52               ` H. Peter Anvin
  0 siblings, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2006-08-01 21:48 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

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




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] include/linux: Defining bool, false and true
  2006-08-01 21:48             ` Jeff Garzik
@ 2006-08-01 21:52               ` H. Peter Anvin
  0 siblings, 0 replies; 13+ messages in thread
From: H. Peter Anvin @ 2006-08-01 21:52 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: ricknu-0, linux-kernel, Andrew Morton, Alexey Dobriyan,
	Vadim Lobanov, Jan Engelhardt, Shorty Porty, Peter Williams,
	Michael Buesch, Pekka Enberg, Stefan Richter, larsbj,
	Paul Jackson, Josef Sipek, Arnd Bergmann, Nicholas Miell,
	Alan Cox, Lars Noschinski

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-08-01 21:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-29 12:19 [PATCH 0/2] A generic boolean-type ricknu-0
2006-07-29 12:32 ` [PATCH 1/2] include/linux: Defining bool, false and true ricknu-0
2006-08-01 19:19   ` H. Peter Anvin
2006-08-01 21:12     ` ricknu-0
2006-08-01 21:20       ` H. Peter Anvin
2006-08-01 21:31         ` Jeff Garzik
2006-08-01 21:42           ` H. Peter Anvin
2006-08-01 21:48             ` Jeff Garzik
2006-08-01 21:52               ` H. Peter Anvin
2006-08-01 21:23     ` Jeff Garzik
2006-08-01 21:41       ` H. Peter Anvin
2006-08-01 21:47         ` Jeff Garzik
2006-07-29 12:36 ` [PATCH 2/2] drivers: Removes colliding boolean definitions ricknu-0

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).