[PATCH] Use more gcc extensions in the Linux headers
[Posted March 14, 2007 by corbet]
| From: |
| Rusty Russell <rusty-AT-rustcorp.com.au> |
| To: |
| lkml - Kernel Mailing List <linux-kernel-AT-vger.kernel.org> |
| Subject: |
| [PATCH] Use more gcc extensions in the Linux headers |
| Date: |
| Fri, 09 Mar 2007 16:56:32 +1100 |
| Cc: |
| Linus Torvalds <torvalds-AT-linux-foundation.org>,
Andrew Morton <akpm-AT-linux-foundation.org> |
| Archive-link: |
| Article,
Thread
|
__builtin_types_compatible_p() has been around since gcc 2.95, and we
don't use it anywhere. This patch quietly fixes that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
diff -r f0ff8138f993 include/linux/kernel.h
--- a/include/linux/kernel.h Fri Mar 09 16:40:25 2007 +1100
+++ b/include/linux/kernel.h Fri Mar 09 16:44:04 2007 +1100
@@ -35,7 +35,9 @@ extern const char linux_proc_banner[];
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) \
+ + sizeof(typeof(int[1 - 2*!!__builtin_types_compatible_p(typeof(arr), \
+ typeof(&arr[0]))]))*0)
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
(
Log in to post comments)