[Top][All Lists]

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

Re: xsize and flexmember

From: Marc Nieper-Wißkirchen
Subject: Re: xsize and flexmember
Date: Thu, 30 Apr 2020 08:39:25 +0200

Thank you very much for your quick response!

Am Do., 30. Apr. 2020 um 00:39 Uhr schrieb Paul Eggert <address@hidden>:
> On 4/29/20 12:29 PM, Marc Nieper-Wißkirchen wrote:
> > It would be great if the flexmember exported another macro, say
> > XFLEXSIZEOF, which returned SIZE_MAX in case of arithmetic overflow.
> Something like this?
> /* Like FLEXSIZEOF, except yield SIZE_MAX on arithmetic overflow,
>    and N might be evaluated more than once.  */
> #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?

>   * If the FLEXSIZEOF calls appears in a ptrdiff_t context it might not
>     return the right value. ptrdiff_t is also a popular way
>     to compute sizes.

Maybe a warning in the comment above the macro's definition would be enough.

> But perhaps it's good enough.

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]