[Top][All Lists]

[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: Wed, 29 Apr 2020 15:39:57 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

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.

  * 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.

But perhaps it's good enough.

reply via email to

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