char (*tp[N])[] ?
18-Aug-93 15:12:50
Sb: #36399-char (*tp[N])[] ?
Fm: Greg Comeau@Comeau Cmptg 72331,3421
To: Doug Walker 71165,2274
> Here's another neat trick if and only if the size of the arrays is
>needed in the same file that they are defined:
>
> char *strings[] = {"A", "B", "C"};
> #define NSTRINGS (sizeof(strings)/sizeof(char *))
Yes, though that macro is too "close" to the id 'strings' for me.
Instead I prefer a more generic version:
#define HBOUND(arr) (sizeof(arr) / sizeof(arr[0])
as it will get the 1st-d of any array.
>Note that you CAN'T use this method if you are declaring the data item
>as an extern and not specifying a number inside the [].
That still remains true here… The array type must be complete by the time
of the sizeof request(s).