Re: small patch for pty.c

From: Horst von Brand (vonbrand@inf.utfsm.cl)
Date: Mon Apr 17 2000 - 12:57:25 EST


"Richard B. Johnson" <root@chaos.analogic.com> said;
> On Mon, 17 Apr 2000, Horst von Brand wrote:
> > "Richard B. Johnson" <root@chaos.analogic.com> said:

> > [...]

> > > Shouldn't the macro be fixed (if broken)? MIN is used a lot in the
> > > source. Several years ago I made one in which the input parameters were
> > > not evaluated twice and it was __static__ __inline__. This was not
> > > accepted, perhaps it's time?

> > An inline function call will cast it's arguments to the type given. This
> > isn't right if somebody wants to get MIN(unsigned, unsigned) and others
> > want MIN(int, int).

> They why did you just post a response that does just that by using
> gcc's 'typeof' ?

It does not. Look:

  #define MIN(x, y) ({typeof x x_ = x; typeof y y_ = y; x_ < y_ ? x_ : y_; })

Here x_ and y_ have the _same_ types as x and y, respectively; and x and y
are evaluated exactly once (perhaps I should write (x) and (y) throughout...)

  static inline int MIN(int x, int y) {return x < y ? x : y;}

This casts everything it gets to int, no way around that; 0xFFFFFFFF -->
-1 < 25, which is wrong if they are unsigned..

-- 
Dr. Horst H. von Brand                       mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 23 2000 - 21:00:11 EST