From a4f3c0f4d96733d81919e1a3c0164dbf56efceb6 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Mon, 19 Jan 2009 23:25:55 +0100 Subject: Update the build_assert macro to use gnulib's version (verify). 2009-01-19 Neal H. Walfield * assert.h (build_assert): Use gnulib's version. --- libc-parts/ChangeLog | 4 ++++ libc-parts/assert.h | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libc-parts/ChangeLog b/libc-parts/ChangeLog index 8e646f6..b1813c0 100644 --- a/libc-parts/ChangeLog +++ b/libc-parts/ChangeLog @@ -1,3 +1,7 @@ +2009-01-19 Neal H. Walfield + + * assert.h (build_assert): Use gnulib's version. + 2009-01-18 Neal H. Walfield * inttypes.h: New file. diff --git a/libc-parts/assert.h b/libc-parts/assert.h index 90aa7a3..6e5d139 100644 --- a/libc-parts/assert.h +++ b/libc-parts/assert.h @@ -24,7 +24,25 @@ #include -#define build_assert(__expr) (void) (sizeof (char[(__expr)? 1 : -1])) +/* The build assert functions are taken from gnulib's + http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=lib/verify.h + . */ +# ifdef __cplusplus +template + struct build_assert_type__ { unsigned int build_assert_error_if_negative_size__: w; }; +# define build_assert_true(R) \ + (!!sizeof (build_assert_type__<(R) ? 1 : -1>)) +# else +# define build_assert_true(R) \ + (!!sizeof \ + (struct { unsigned int build_assert_error_if_negative_size__ \ + : (R) ? 1 : -1; \ + })) +# endif + +# define build_assert(R) \ + extern int (* build_assert_function__ (void)) [build_assert_true (R)] + #if defined(_L4_TEST_ENVIRONMENT) || defined(_ENABLE_TESTS) # include_next -- cgit v1.2.3