In C language macro for getting number of array elements is well known and looks like this:
uint32_t buffer[10];
#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
size_t size = ARRAY_SIZE(buffer);
The question is, is there any universal macro for getting array elements or returning just one when it's used on variable ? I mean following usage of macro :
uint32_t buffer[10];
uint32_t variable;
#define GET_ELEMENTS(x) ???
size_t elements_of_array = GET_ELEMENTS(buffer); // returns 10
size_t elements_of_variable = GET_ELEMENTS(variable); // returns 1
Does anybody know the solution ?
I've edited my question because it was wrongly formulated, BTW I know that I can use :
sizeof(variable)/sizeof(uint32_t)
Question is how to combine it in one macro or maybe inline function is better solution ?