Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/kern



On Tue, Jan 31, 2012 at 07:32:52PM +0000, Alexander Nasonov wrote:
> What about something like this (untested)?
> 
> /*
>  * Return a size of a structure s with flexible-array member m
>  * with n elements.
>  */
> #define sizeof_fam(s, m, n) (sizeof(s) + sizeof(((s *)NULL)->m[0]) * (n))

That's still not necessarily optimal, depending on the padding rules of
the platform. You want to do offsetof(s, m[0]) + n * sizeof((s*)NULL->m[0]).

Joerg


Home | Main Index | Thread Index | Old Index