linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [IDEA+RFC] Possible solution for min()/max() war
       [not found] <200108291905.f7TJ59T11456@wildsau.idv-edu.uni-linz.ac.at>
@ 2001-08-29 19:11 ` Herbert Rosmanith
  2001-08-29 20:07   ` [IDEA+RFC] Possible solution for min()/max() war -- I like this Christopher Friesen
  0 siblings, 1 reply; 2+ messages in thread
From: Herbert Rosmanith @ 2001-08-29 19:11 UTC (permalink / raw)
  To: linux-kernel

> From: Helge Hafting <helgehaf@idb.hist.no>
> X-Mailer: Mozilla 4.76 [no] (X11; U; Linux 2.4.10-pre1 i686)
> X-Accept-Language: no, en
> To: Brad Chapman <kakadu_croc@yahoo.com>, linux-kernel@vger.kernel.org
> Subject: Re: [IDEA+RFC] Possible solution for min()/max() war
> References: <20010828204207.12623.qmail@web10908.mail.yahoo.com>
> Sender: linux-kernel-owner@vger.kernel.org
> Precedence: bulk
> X-Mailing-List: 	linux-kernel@vger.kernel.org
> 
> Brad Chapman wrote:
> > 
> > Then why, IIRC, are the kernel hackers so upset about how
> > the three-arg macros _prevent_ signed/unsigned comparisons?
> > Apparently the ability to compare
> > signed/unsigned variables must have _some_ significance....
> 
> You are misunderstanding this.
> It is possible to write something that _looks like_ a signed to unsigned
> comparison, i.e.:
> int a;
> unsigned int b;
> ...
> x = min(a,b);
> 
> Looks like a signed to unsigned comparison - but it isn't!
> 
> You see, the compiler always does an _implicit_ cast in cases like this.
                             ^^^^^^^^^^^^^^^^^^^^^

if that's your concern, we can easily fix this by still moving min/max
to its same form.


#define type_min(type,x,y) \
        ({ type __x = (x), __y = (y); __x < __y ? __x: __y; })
#define type_max(type,x,y) \
        ({ type __x = (x), __y = (y); __x > __y ? __x: __y; })

#define min(x,y) type_min(typeof(x),x,y)
#define max(x,y) type_max(typeof(x),x,y)

no _implicit_ cast and ...

> One of the arguments gets changed invisibly, and that is what kernel
> developers are so upset about.  You don't really know which one without
> thinking hard about it, and that is a source of many hard-to-find bugs.

... joy, we would even know which one.


-- 
mfg,
Dipl.-Ing. H.Rosmanith                    Karrer & Partner Gesellschaft mbH
Freistaedter Str. 236, A-4040 Linz,                   Tel. +43/732/75 71 30
                                                      Fax. +43/732/75 71 44


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [IDEA+RFC] Possible solution for min()/max() war -- I like this
  2001-08-29 19:11 ` [IDEA+RFC] Possible solution for min()/max() war Herbert Rosmanith
@ 2001-08-29 20:07   ` Christopher Friesen
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Friesen @ 2001-08-29 20:07 UTC (permalink / raw)
  To: Herbert Rosmanith; +Cc: linux-kernel

Herbert Rosmanith wrote:

> #define type_min(type,x,y) \
>         ({ type __x = (x), __y = (y); __x < __y ? __x: __y; })
> #define type_max(type,x,y) \
>         ({ type __x = (x), __y = (y); __x > __y ? __x: __y; })
> 
> #define min(x,y) type_min(typeof(x),x,y)
> #define max(x,y) type_max(typeof(x),x,y)
> 
> no _implicit_ cast and ...
> 
> > One of the arguments gets changed invisibly, and that is what kernel
> > developers are so upset about.  You don't really know which one without
> > thinking hard about it, and that is a source of many hard-to-find bugs.
> 
> ... joy, we would even know which one.

I think this makes a lot of sense.  The explicit version could be preferred, but
for the implicit version we at least know that what type will be used for it and
it won't immediately break things that are still using the old-style min/max.


-- 
Chris Friesen                    | MailStop: 043/33/F10  
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-29 20:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200108291905.f7TJ59T11456@wildsau.idv-edu.uni-linz.ac.at>
2001-08-29 19:11 ` [IDEA+RFC] Possible solution for min()/max() war Herbert Rosmanith
2001-08-29 20:07   ` [IDEA+RFC] Possible solution for min()/max() war -- I like this Christopher Friesen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).