tables with 0 elements
Posted on 2001-09-17
Below is a snippet of code. It compiles with gcc, but
not cc. My question is, why doesn't cc like it, and how
do I modify the declaration of the table to get the
outcome I want (which is to have 'x = 0').
(If you're curious - the idea is to have a table such that an action is performed for each entry in the table. If there are zero entries, then zero actions are performed. This is intended to be a default case - other people or perhaps even a script might add elements to the table later depending on a particular need.)
Any help would be appreciated.
MYSTRUCT mytable =
#define num_elements(a) (sizeof(a)/sizeof(a))
int x = num_elements(mytable);
printf("number of elements: %d\n", x);