Defining a Macro to Return the Number of Elements in an Array
As a convenience I attempted to define this macro for providing the number of elements in a static array of an arbitrary type:
This did not work because the size of operator cannot be directly used in a macro. I have seen here:
http://cs-fundamentals.com/tech-interview/c/implement-sizeof-operator-in-c.php
how to create a macro that would work for the numerator of the above #define:
But what about the denominator which needs to be the size of the type? Would this work?
If it did work would it still work for a single element array?
Would the above method be more expensive in processing time than giving up on the use of a macro to do this and expanding to the equivalent of (sizeof(AR)/sizeof(*AR) manually?