All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [RFC] Regarding min/max
Date: Sat, 03 Feb 2007 19:01:41 +0000	[thread overview]
Message-ID: <45C4DC15.9050308@student.ltu.se> (raw)
In-Reply-To: <45C3E402.3000307@student.ltu.se>

Jaco Kroon wrote:
> Robert P. J. Day wrote:
>   
>> On Sat, 3 Feb 2007, Richard Knutsson wrote:
>>     
>>> Hi
>>>
>>> Regarding converting:
>>>
>>> 	a = x < y ? x : y;
>>>
>>> with
>>> 	a = min(x, y);
>>> and etc.
>>>
>>> What about variables in structs? It seem to not like the multiple
>>> lines in min()/max(), so why not introduce something like: #define
>>> __min(x,y) ((x) < (y) ? (x) : (y)) (and use __min() in min() also)?
>>> Then there would be no problem to clean up in the structs + the
>>> underscores should make people aware it does not type-check.
>>>
>>> Just a thought
>>> /Richard Knutsson
>>>       
>
> 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; })
>
> #define max(x,y) ({ \
>     typeof(x) _x = (x); \
>     typeof(y) _y = (y); \
>     (void) (&_x = &_y);        \
>     _x > _y ? _x : _y; })
>
> So one just need to convert to using these :).
>
> Jaco
>   
Hmm, seems I pushed the "Reply" instead of "Reply all"-button when 
answering Randy.
I tried to recreate the compile-failure (was some time ago since it 
happened) when using min()/max() in a struct but it happily compiled it 
so (thankfully) you are correct, just need to use min()/max(). :)

Richard Knutsson

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2007-02-03 19:01 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 [this message]
2007-02-03 20:04 ` Srdjan Todorovic
2007-02-03 20:10 ` Jaco Kroon

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=45C4DC15.9050308@student.ltu.se \
    --to=ricknu-0@student.ltu.se \
    --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.