[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <956ab0e63b8340669c31d2452830b7f3@AcuMS.aculab.com>
Date: Thu, 24 Aug 2023 08:53:25 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Mahmoud Matook' <mahmoudmatook.mm@...il.com>
CC: 'Willem de Bruijn' <willemdebruijn.kernel@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
"kuba@...nel.org" <kuba@...nel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"davem@...emloft.net" <davem@...emloft.net>,
"pabeni@...hat.com" <pabeni@...hat.com>,
"edumazet@...gle.com" <edumazet@...gle.com>,
"shuah@...nel.org" <shuah@...nel.org>,
"linux-kernel-mentees@...ts.linuxfoundation.org"
<linux-kernel-mentees@...ts.linuxfoundation.org>
Subject: RE: [PATCH 1/2] selftests: Provide local define of min() and max()
From: Mahmoud Matook
> Sent: Wednesday, August 23, 2023 8:36 PM
...
> I tried to use the relaxed version provided in the shared patchset link
> besides not able to use is_constexpr(), I'm not able to use
> __UNIQUE_ID() also. It's definded inside include/linux/compiler-gcc.h
> and it uses another macro __PASTE() which is defined inside
> include/linux/compiler_types.h.
> not sure what to do next
>
> - bring those macros definitions to able to use the relaxed version.
> - if the most important point for min/max defines inside selftests is to
> avoid multiple evaluation is the below version acceptable?
>
> #define min(x, y) ({ \
> typeof(x) _x = (x); \
> typeof(y) _y = (y); \
> _x < _y ? _x : _y; \
> })
>
> #define max(x, y) ({ \
> typeof(x) _x = (x); \
> typeof(y) _y = (y); \
> _x > _y ? _x : _y; \
> })
Those are a reasonable pair.
If you want a signed-ness check the:
_Static_assert(is_signed_type(typeof(a)) == is_signed_type(typeof(b)), "min/max signednesss")
check should just drop into the above.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists