RE: [PATCH 1/1] minmax.h: Slightly relax the type checking done by min() and max().

From: David Laight
Date: Mon Nov 28 2022 - 04:14:12 EST


From: David Laight
> Sent: 25 November 2022 15:01
>
> Slightly relax the type checking done by min() and max().
> - Promote signed/unsiged char/short to int prior to the type test.
> This matches what the compiler does before doing the comparison.
> - Skip the type test if either argument is a positive 'int' constant.
> Instead cast the constant to 'int', the compiler may promote it
> back to 'unsigned int' when doing the test.
>
> Reduces the need to use min_t/max_t() and the possibly unwanted
> side effects if a type that is too small is specified.
>
...
> +#define __cmp(x, y, op) __cmp_maybe_int(__maybe_int_cast(x), __maybe_int_cast(y), op)
>
> #define __cmp_once(x, y, unique_x, unique_y, op) ({ \
> typeof(x) unique_x = (x); \

self nak.
That has to be done as:
typeof(__maybe_int_cast(x)) unique_x = (x);

I will send a V2.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)