Re: G_ARRAY_LENGTH for glib.h?



> I think that the runtime check is better than no check at all. That problem
> with getting 1 is not a theoretical one. It has happened to me a lot. Here's
> another variation:
> 
>     #define G_N_ELEMENTS(array) (G_IS_STATIC_ARRAY(array) \
>         ? (g_error("G_N_ELEMENTS called on non-array"), 0) \
>: sizeof(array) / sizeof((array)[0])
> 
> Since this doesn't use g_assert, it would need to be inside a
> G_DISABLE_ASSERT wrapper, or have its own symbol to disable the check and
> fall back to the simpler version.
> 
>     -- Darin

I don't think it has to be inside a G_DISABLE_ASSERT wrapper
very much since the g_error should be entirely optimized
away by the compiler.

- Dave



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