2 ms·
Your comment made me look at the article. I saw this line > Can we somehow not require the user to specify the size of the pollset in advance? The answer for
by Gibbon1 4y ago
Your comment made me look at the article. I saw this line
> Can we somehow not require the user to specify the size of the pollset in advance?
The answer for gnu99 is yes.
// will barf if fed a pointer
#define sizeof_array(arr) \
(sizeof(arr) / sizeof((arr)[0]) \
+ sizeof(typeof(int[1 - 2 * \
!!__builtin_types_compatible_p(typeof(arr), \
typeof(&arr[0]))])) * 0)
typedef struct
{
int x, y;
} Foo;
Foo foo[] =
{
{ .x = 10, .y = 20},
{ .x = 11, .y = 23}
};
foo_cnt = sizeof_array(foo); // foo_cnt == 2
One of the reasons why I think the C standards committee needs to be fired is because sizeof_array should have been made part of the language 20 years ago.