Re: xsize and flexmember

2020-05-01 Thread Paul Eggert
On 5/1/20 4:13 PM, Bruno Haible wrote: > For subtraction, I would not define anything - I see no use for subtracting > possibly overflown values. That would simplify things. I assume we would want saturated multiplication, though. And we could use INT_ADD_SAT (INT_MULTIPLY_SAT (m, n), -1) to comp

Re: xsize and flexmember

2020-05-01 Thread Bruno Haible
Paul Eggert wrote: > > I'm open to this. What prefix would you propose instead of 'x'? > > The usual English-language name for this sort of thing is "saturation > arithmetic", but SATURATED_ADD is kind of long. LLVM uses "sat" for saturated > operations, perhaps the prefix "SAT" will do. Fine wit

Re: xsize and flexmember

2020-05-01 Thread Paul Eggert
On 5/1/20 2:09 AM, Bruno Haible wrote: > I'm open to this. What prefix would you propose instead of 'x'? The usual English-language name for this sort of thing is "saturation arithmetic", but SATURATED_ADD is kind of long. LLVM uses "sat" for saturated operations, perhaps the prefix "SAT" will do.

Re: xsize and flexmember

2020-05-01 Thread Paul Eggert
On 5/1/20 2:20 AM, Marc Nieper-Wißkirchen wrote: > I think that size_t calculations are still the most important ones. In other apps I've found many other integer types where overflow is important, including ptrdiff_t, int, long, and intmax_t. ptrdiff_t is the big one, as its use is supplanting si

Re: xsize and flexmember

2020-05-01 Thread Marc Nieper-Wißkirchen
Am Fr., 1. Mai 2020 um 11:09 Uhr schrieb Bruno Haible : > > Paul Eggert wrote: > > I realize we have dueling conventions here, but would prefer that > > saturated size_t arithmetic have a longer prefix or suffix than just "x". > > I'm open to this. What prefix would you propose instead of 'x'? Wha

Re: xsize and flexmember

2020-05-01 Thread Bruno Haible
Paul Eggert wrote: > I realize we have dueling conventions here, but would prefer that > saturated size_t arithmetic have a longer prefix or suffix than just "x". I'm open to this. What prefix would you propose instead of 'x'? Generally, 'xsize' has not caught on as I had expected. It is still a

Re: xsize and flexmember

2020-05-01 Thread Marc Nieper-Wißkirchen
Am Fr., 1. Mai 2020 um 00:20 Uhr schrieb Paul Eggert : > > On 4/30/20 2:01 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) FLEXS

Re: xsize and flexmember

2020-04-30 Thread Paul Eggert
On 4/30/20 2:01 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) > > Why do you write "(n) <=

Re: xsize and flexmember

2020-04-30 Thread Marc Nieper-Wißkirchen
Am Do., 30. Apr. 2020 um 22:49 Uhr schrieb Paul Eggert : > > 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

Re: xsize and flexmember

2020-04-30 Thread Paul Eggert
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

Re: xsize and flexmember

2020-04-29 Thread Marc Nieper-Wißkirchen
Thank you very much for your quick response! Am Do., 30. Apr. 2020 um 00:39 Uhr schrieb Paul Eggert : > > 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.

Re: xsize and flexmember

2020-04-29 Thread Paul Eggert
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 eval

xsize and flexmember

2020-04-29 Thread Marc Nieper-Wißkirchen
The flexmember module provides the macro FLEXSIZEOF to calculate an appropriate size to malloc a struct with a flexible array member. Overflow is reported differently than with the xsize module, which provides size_overflow_p. It would be great if the flexmember exported another macro, say XFLEXS