Re: offsetof() in array sizes
Carles Cufi
Hi Andrew,
toggle quoted message
Show quoted text
-----Original Message-----Thanks for the reply, here's a patch below. Thanks, Carles From ddd980e2418053ae346f25deb8ae029f50cb20b3 Mon Sep 17 00:00:00 2001 From: Carles Cufi <carles.cufi(a)nordicsemi.no> Date: Subject: [PATCH 1/1] lib: Use offsetof() builtin with GCC The default offsetof() implementation generates a warning (variably modified <variable> 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 <carles.cufi(a)nordicsemi.no> --- 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 2e1ef66..bcc0a6e 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__ */ -- 1.9.1 |
|