CERT secure coding practices requires that the secure programmer prefer inline or static functions to function-like macros. So my question is: How do you convert
#define ARRAYSIZE(a) sizeof(a)/sizeof(a[0]) to an inline function?
would this work?
inline int arraysize (void* a) { return (sizeof(*a)/sizeof(*a[0])); }
No that would not work.
It is impossible to convert the ARRAYSIZE macro to a function because any function you write will have a point as an argument(like yours) not an array.
Try compiling your function, it wont.
Anyway the whole point here is that the the sizeof operator has to have visibility of the actual array and the only way to achieve that is to have thesizeof operator in the code, a function, even an inline one, just doesn't cut it.