From 1980b7bb0ffee0750ed832fc1b474c6ae6e85b00 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Tue, 23 Aug 2016 09:41:17 -0700 Subject: [PATCH] lib: Use offsetof() builtin with GCC The default offsetof() implementation generates a warning (variably modified at file scope) when used in to define the size of an array. By using this builtin with GCC we avoid the warning and make sure no variable-size arrays are used. Change-Id: Iae215f777241f7daaa061067230086dffaa8311d Signed-off-by: Carles Cufi --- lib/libc/minimal/include/stddef.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libc/minimal/include/stddef.h b/lib/libc/minimal/include/stddef.h index 2e1ef666fbb..bcc0a6e9132 100644 --- a/lib/libc/minimal/include/stddef.h +++ b/lib/libc/minimal/include/stddef.h @@ -27,6 +27,10 @@ typedef int ptrdiff_t; #endif +#if defined(__GNUC__) +#define offsetof(type, member) __builtin_offsetof(type, member) +#else #define offsetof(type, member) ((size_t) (&((type *) NULL)->member)) +#endif #endif /* __INC_stddef_h__ */