Re: [RFC][PATCH] A generic boolean

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[email protected] wrote:
A first step to a generic boolean-type. The patch just introduce the bool (in

Since gcc supports boolean types and can optimize for such, introducing bool is IMO a good thing.


-Why would we want it?
-There is already some how are depending on a "boolean"-type (like NTFS). Also,
it will clearify functions who returns a boolean from one returning a value, ex:
bool it_is_ok();
char it_is_ok();
The first one is obvious what it is doing, the secound might return some sort of
status.

A better reason is that there is intrinsic compiler support for booleans.


-Why false and not FALSE, why not "enum {...} bool"
-They are not #define(d) and shouldn't because it is a value, like 'a'. But
because it is just a value, then bool is just a variable and should be able to
handle 0 and 1 equally well.

Well, this is _my_ opinion, it may be totally wrong. If so, please tell me ;)

Yes, I know about Andrew's try to unify TRUE and FALSE, did read the thread with
interest (that's from where I got to know about _Bool). But mostly (then still
on the subject) was some people did not want FALSE and TRUE instead of 0 and 1.
I look at it as: 'a' = 97, if someone like to write 97 instead of 'a', please do
if you find it easier to read. I, on the other hand, think it is easier with
'a', false/FALSE, NULL, etc.

We should follow what C99 directs.


diff --git a/include/asm-i386/types.h b/include/asm-i386/types.h
index 4b4b295..e35709a 100644
--- a/include/asm-i386/types.h
+++ b/include/asm-i386/types.h
@@ -10,6 +10,15 @@ typedef unsigned short umode_t;
  * header files exported to user space
  */
+#if defined(__GNUC__) && __GNUC__ >= 3
+typedef _Bool bool;
+#else
+#warning You compiler doesn't seem to support boolean types, will set 'bool' as
an 'unsigned char'
+typedef unsigned char bool;
+#endif
+
+typedef bool u2;

NAK.  gcc >= 3 is required by now, AFAIK.

Also, you don't want to force 'unsigned char' on code, because often code prefers a machine integer to something smaller than a machine integer.


diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index b3a2cad..5e5c611 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -10,6 +10,8 @@ #else
 #define NULL ((void *)0)
 #endif
+enum { false = 0, true = 1 } __attribute__((packed));

How is 'packed' attribute useful here?

	Jeff


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux