On 18/10/10 18:29, Paul Eggert wrote: > On 10/18/10 04:53, Pádraig Brady wrote: > >> /* Like sizeof, except that it treats a variable sized array >> as a pointer rather than determining the size at runtime. */ >> #define CT_SIZEOF(x) (__builtin_constant_p(sizeof x) ? sizeof x: sizeof >> (void*)) > > I don't see how this would work. If x is a variable-sized > array, CT_SIZEOF(x) is not a constant expression, according > to the C rules, because for A?B:C to be a constant expression, > B and C both have to be constant expressions.
I did verify it, but on gcc 4.1.3. I've just now checked that gcc 3.0 does also constant fold the above, while gcc 2.95 does not. > Besides, there's really not that much need to be worried about > older GCC compilers. They are being upgraded all the time, and > the problem will go away. In the meantime, we're going to be > catching the errors anyway, since we'll be using the newer compilers. I understand that. My main reasoning was to have the simpler solution as a stepping stone to understanding the more complicated one. cheers, Pádraig.