offsetof() in array sizes


Carles Cufi
 

Hi there,

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.

Thanks,

Carles

Join devel@lists.zephyrproject.org to automatically receive all group messages.