lkml.org 
[lkml]   [2008]   [Sep]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 5/5 ver2] debug: BUILD_BUG_ON: error on non-const expressions
    >>> Boaz Harrosh <bharrosh@panasas.com> 03.09.08 10:57 >>>
    >Jan Beulich wrote:
    >>>>> Boaz Harrosh <bharrosh@panasas.com> 02.09.08 17:57 >>>
    >>> -#define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
    >>> +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
    >>> +
    >>> +/* Force a compilation error if condition is true */
    >>> +#define BUILD_BUG_ON(e) \
    >>> + do { struct {int:-!!(e); } x __maybe_unused;} while(0)
    >>
    >> As indicated before, you should at the very least use __x as the variable
    >> name.
    >>
    >
    >The name does not matter. The scope of x is confined to the do {} while()
    >and will not interfere with any local or global name.

    I'm sorry to repeat this: If x is #define-d to anything but a simple identifier,
    this will break no matter that it's in a private scope. The absence of any
    identifier was a benefit of the sizeof() approach here.

    Jan



    \
     
     \ /
      Last update: 2008-09-03 12:21    [W:0.021 / U:4.984 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site