tech-kern archive   Re: proposal: some pointer and arithmetic
utilities     Date: Fri, 22 Mar 2013 09:08:55 +0200    From:
Alan Barrett <>     I don't really see the point of offsetin --
if you have a struct     that ends with an array of 1 element,
but you want to allocate     enough space for the struct plus an
array of >1 elements, then why     not just do the arithmetic
without a macro, and if you do need a     macro, then why not
give it a name that sounds more like "sizeof"?  We could do the
arithmetic without a macro, but it's more complicated to get
that correct.  Compare          struct foo *f =
alloc(offsetin(*f, f_data[n]));           struct foo *f =
alloc(sizeof(*f) + sizeof(typeof(f->f_data[0])[n]));  Of course,
if I want to avoid typeof (as we seem to do throughout our
tree), I have to know the type of the flexible array member's
elements a priori, and the compiler won't check that for me:
struct foo *f = alloc(sizeof(*f) + sizeof(double[n]));  This
assumes that f_data is a C99 flexible