lkml.org 
[lkml]   [2012]   [Nov]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] utilize _Static_assert() for BUILD_BUG_ON() when the compiler supports it
Date
Jan Beulich <JBeulich@suse.com> writes:
> This makes the resulting diagnostics quite a bit more useful.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Nice. I'm a bit disappointed we can't just treat _Static_assert() as
void, like:

#define BUILD_BUG_ON_ZERO(e) (_Static_assert(!(e), "!(" #e ")"), 0)

> @@ -54,6 +61,15 @@ struct pt_regs;
> */
> #ifndef __OPTIMIZE__
> #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
> +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
> +#define __build_bug_on_failed(n) __build_bug_on_##n##_failed
> +#define _BUILD_BUG_ON(n, condition) \
> + do { \
> + extern void __compiletime_error(#condition) \
> + __build_bug_on_failed(n)(void); \
> + if (condition) __build_bug_on_failed(n)(); \
> + } while(0)
> +#define BUILD_BUG_ON(condition...) _BUILD_BUG_ON(__COUNTER__, ##condition)
> #else
> extern int __build_bug_on_failed;
> #define BUILD_BUG_ON(condition) \

Why does this depend on gcc version? Looks like residue from an attempt
to use _Static_assert here?

Thanks,
Rusty.


\
 
 \ /
  Last update: 2012-11-05 05:02    [W:0.092 / U:1.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site