From: David Laight <David.Laight@ACULAB.COM>
To: 'Mahmoud Matook' <mahmoudmatook.mm@gmail.com>
Cc: 'Willem de Bruijn' <willemdebruijn.kernel@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"kuba@kernel.org" <kuba@kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"davem@davemloft.net" <davem@davemloft.net>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"edumazet@google.com" <edumazet@google.com>,
"shuah@kernel.org" <shuah@kernel.org>,
"linux-kernel-mentees@lists.linuxfoundation.org"
<linux-kernel-mentees@lists.linuxfoundation.org>
Subject: RE: [PATCH 1/2] selftests: Provide local define of min() and max()
Date: Thu, 24 Aug 2023 08:53:25 +0000 [thread overview]
Message-ID: <956ab0e63b8340669c31d2452830b7f3@AcuMS.aculab.com> (raw)
In-Reply-To: <20230823193545.nrzlbsa32hm4os4k@mmaatuq-HP-Laptop-15-dy2xxx>
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)
next prev parent reply other threads:[~2023-08-24 8:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-19 19:50 [PATCH 0/2] selftests: Introduce common min()/max() and apply them in net tests Mahmoud Maatuq
2023-08-19 19:50 ` [PATCH 1/2] selftests: Provide local define of min() and max() Mahmoud Maatuq
2023-08-20 15:15 ` Willem de Bruijn
2023-08-21 13:04 ` David Laight
2023-08-22 14:34 ` Willem de Bruijn
2023-08-22 14:48 ` David Laight
2023-08-23 19:35 ` Mahmoud Matook
2023-08-24 8:53 ` David Laight [this message]
2023-08-19 19:50 ` [PATCH 2/2] selftests/net: replace ternary operator with min()/max() Mahmoud Maatuq
2023-08-20 15:10 ` Willem de Bruijn
2023-08-23 19:40 ` Mahmoud Matook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=956ab0e63b8340669c31d2452830b7f3@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mahmoudmatook.mm@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®