From: Jaco Kroon <jaco@kroon.co.za>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [RFC] Regarding min/max
Date: Sat, 03 Feb 2007 20:10:20 +0000 [thread overview]
Message-ID: <45C4EC2C.4030007@kroon.co.za> (raw)
In-Reply-To: <45C3E402.3000307@student.ltu.se>
Srdjan Todorovic wrote:
> Hi,
>
> On Sat, 3 Feb 2007, Jaco Kroon wrote:
>
>
>>from include/linux/kernel.h:
>>
>>/*
>> * min()/max() macros that also do
>> * strict type-checking.. See the
>> * "unnecessary" pointer comparison.
>> */
>>#define min(x,y) ({ \
>> typeof(x) _x = (x); \
>> typeof(y) _y = (y); \
>> (void) (&_x = &_y); \
>> _x < _y ? _x : _y; })
>
> I don't quite understand that macro, specificaly the (void) (&_x = &_y); line.
> The comment says that this macro does strict type-checking. From what I
> can see, it does a comparison on the two automatic variables, but throws
> away the result. So thus is essentially a no-op.
Exactly. But it verifies that a pointer to each of the two can be
compared, and that can only happen if the pointer types are identical.
Whilst a int can automatically be "upgraded" to long (for example), int*
and long* are two distinct types. So the pointer comparison is thrown
away, since that really isn't the comparison we're after, then _x < _y
actually compares the data and returns the appropriate one.
> If x and y are two different types, the compiler would complain with a
> warning/error because there was no cast. Is that the strict type-checking
> that the comment mentions, and did I understand this correctly?
Jaco
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
prev parent reply other threads:[~2007-02-03 20:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-03 1:23 [KJ] [RFC] Regarding min/max Richard Knutsson
2007-02-03 1:45 ` Randy Dunlap
2007-02-03 7:42 ` Robert P. J. Day
2007-02-03 8:38 ` Jaco Kroon
2007-02-03 19:01 ` Richard Knutsson
2007-02-03 20:04 ` Srdjan Todorovic
2007-02-03 20:10 ` Jaco Kroon [this message]
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=45C4EC2C.4030007@kroon.co.za \
--to=jaco@kroon.co.za \
--cc=kernel-janitors@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.