Re: G_ARRAY_LENGTH for glib.h?




Darin Adler <darin@bentspoon.com> writes:

> Any thoughts about the possibility of adding this macro to glib.h?
> 
>     #define G_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
> 
> I use this all the time and thought it might be a good candidate.

Yes, I think this macro would be good to have. (I often end
up defining it myself in various places.)

The name is a little problematical ... G_ARRAY_LENGTH() is
too long, and also belongs to the GArray namespace,

It's defined 30 separate times in GNOME CVS as #define ELEMENTS
so that a pretty clear indication that G_ELEMENTS would
not be a bad name. 

In fact, if we had done so earlier, we might have been able to
sneak it in is as simply ELEMENTS, along with TRUE, FALSE, MIN, MAX,
and CLAMP. But at this point, that would clearly cause some
problems, so G_ELEMENTS() is probably safest.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]