[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xsize and flexmember
From: |
Paul Eggert |
Subject: |
Re: xsize and flexmember |
Date: |
Thu, 30 Apr 2020 13:49:31 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
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".