On Wed, Oct 02, 2013 at 06:44:44PM -0300, Flavio Leitner wrote: > On Wed, Oct 02, 2013 at 12:34:53PM -0700, Ben Pfaff wrote: > > On Wed, Oct 02, 2013 at 02:40:09AM -0300, Flavio Leitner wrote: > > > GCC provides two useful builtin functions that can help > > > to improve array size checking during compilation. > > > > > > This patch contains no functional changes, but it makes > > > it easier to detect mistakes. > > > > > > Signed-off-by: Flavio Leitner <f...@redhat.com> > > > > This seems simpler: > > > > --8<--------------------------cut here-------------------------->8-- > > > > From: Flavio Leitner <f...@redhat.com> > > Date: Wed, 2 Oct 2013 02:40:09 -0300 > > Subject: [PATCH] util: use gcc builtins to better check array sizes > > > > GCC provides two useful builtin functions that can help > > to improve array size checking during compilation. > > > > This patch contains no functional changes, but it makes > > it easier to detect mistakes. > > > > Signed-off-by: Flavio Leitner <f...@redhat.com> > > Signed-off-by: Ben Pfaff <b...@nicira.com> > > --- > > lib/util.h | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/lib/util.h b/lib/util.h > > index 0db41be..8978bdb 100644 > > --- a/lib/util.h > > +++ b/lib/util.h > > @@ -87,8 +87,18 @@ void ovs_assert_failure(const char *, const char *, > > const char *) NO_RETURN; > > > > extern const char *program_name; > > > > +#ifdef __GNUC__ > > +/* Fails a build assertion if ARRAY is not an array type. */ > > +#define ARRAY_CHECK(ARRAY) \ > > + BUILD_ASSERT(!__builtin_types_compatible_p(typeof(ARRAY), \ > > + typeof(&ARRAY[0]))) > > I thought about using the BUILD_ASSERT(), but it doesn't seem to > work in all contexts that ARRAY_SIZE() is being used, so I wrote > those new macros. > > Did it work for you? If so, in which branch? I am on master and it > breaks here:
Argh. It seems I tested this only with Clang, which didn't complain. I applied your patch to master, thank you. _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev