Re: offsetof() in array sizes

Boie, Andrew P

If one includes a offsetof() statement inside a macro that is then used to size
an array, the following warning is issued by GCC:

warning: variably modified <VAR_NAME> at file scope

The fix for this, at least for GCC, is to use:

#if defined(__GNUC__)
#define offsetof(s, m) __builtin_offsetof(s, m) #else #define offsetof(s, m)
((size_t)(&(((s *)0)->m))) #endif

Any thoughts about this particular matter? We'd like to use offsetof() when
sizing arrays in the BLE Controller but we don't want to duplicate the
offsetof() macro.
I don't see a problem with replacing the existing definition in the minimal libc with the corrected version above.
Can you send a patch against lib/libc/minimal/include/stddef.h?


Join to automatically receive all group messages.