lkml.org 
[lkml]   [2007]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Use more gcc extensions in the Linux headers
On Fri, Mar 09, 2007 at 04:56:32PM +1100, Rusty Russell wrote:
> __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)

This needs a comment explaning why we're doing this, and maybe a little
explanation of the combination of gcc magic and C trickery used to implement
it to the brave non-uberhacker people trying to understand linux headers.

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

\
 
 \ /
  Last update: 2007-03-09 08:55    [W:0.195 / U:0.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site