How can I determine how many elements there are in an array of compound literals. I'm using the well known macro sizeof(a)/sizeof(a[0]);
but keep getting 1
.
#include <stdio.h>
typedef struct {
int enable;
const char * const *message;
} table_s;
static const table_s table[] =
{
{ 1, (const char * const []){ "Message 1", "Message 2" } },
{ 1, (const char * const []){ "Message 1", "Message 2", "Message 3"} }
};
#define NELEMS(x) (sizeof(x) / sizeof(x[0]))
int main(int argc, char *argv[]) {
printf("%d\n", NELEMS(table[0].message));
printf("%d\n", NELEMS(table[1].message));
return 0;
}