Standard alternative to sizeof(array)/sizeof(array)?
Is there a good standard alternative to the
used for determining the size of an array?
Well sometimes you see:
but this is only somewhat shorter and not hardly better.
What I'm looking for is a standard macro in a standard header, something like
but there is no such thing in stddef.h where offsetof is defined.
#define lenof(a) (sizeof(a)/sizeof((a)))
There is the further problem, that
will return 2 not 8 on most targets, due to the fact that foo is equal to
int foo(short array)
which is a rather obscure feature of C.
int foo(short *array)