lkml.org 
[lkml]   [2012]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [RFC 3/3] kernel.h: use new typechecking macros in min()/max() and friends
    On Sat, Apr 14, 2012 at 3:14 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
    > Convert to using new typechecking macros in kernel.h. This prevents code
    > duplication and makes the modified macros (easily) readable again.
    >
    >  #define min(x, y) ({                           \
    > -       typeof(x) _min1 = (x);                  \
    > -       typeof(y) _min2 = (y);                  \
    > -       (void) (&_min1 == &_min2);              \
    > -       _min1 < _min2 ? _min1 : _min2; })
    > +       typecmp2((x), (y));                             \
    > +       (x) < (y) ? (x) : (y); })

    They may be readable, but they are total shit.

    You now evaluate 'x' and 'y' multiple times, so if they are function
    calls or contain other side effects (like "a++" etc), you get the
    wrong result.

    So no. Hell no.

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

    \
     
     \ /
      Last update: 2012-04-14 23:21    [W:0.030 / U:0.192 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site