On 4/29/20 11:39 PM, Marc Nieper-Wißkirchen wrote:

>> #define XFLEXSIZEOF_XSIZE(type, member, n) \
>>   (((n) <= FLEXSIZEOF (type, member, n) \
>>     && FLEXSIZEOF (type, member, n) <= (size_t) -1) \
>>    ? (size_t) FLEXSIZEOF (type, member, n) : (size_t) -1)
>>
>> A couple of problems with this approach:
>>
>>   * It evaluates N more than once.
> 
> Couldn't this be solved by calling a static function that would be
> subject to be inlined?

I don't offhand see how to get that to work if n exceeds SIZE_MAX.

> Why would you prefer the (longer) name XFLEXSIZEOF_XSIZE vs XFLEXSIZEOF?

It's specialized for size_t computations, and is not in general suitable for
ptrdiff_t or other types. Also, elsewhere in Gnulib a leading "x" means the
function signals an error if overflow occurs, and that's not what's happening
here. I realize we have dueling conventions here, but would prefer that
saturated size_t arithmetic have a longer prefix or suffix than just "x".

Reply via email to