Re: [PATCH 01/01] staging: replace open-coded ARRAY_SIZEs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 11, 2012 at 5:09 AM, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> On Wed, Apr 11, 2012 at 03:14:37AM -0600, Jim Cromie wrote:
>> My larger goal was to find use-cases for this:
>> (sent to LKML a day or 2 ago)
>>
>> +/**
>> + * BUILD_BUG_DECL - check declared objects
>> + * @name: distinguishes multiple uses at same scope.
>> + * @cond: false expr, typically like sizeof(a) != sizeof(b)
>> + *
>> + * This works at file-scope too, and supports checks like:
>> + * BUILD_BUG_DECL(foo, sizeof(a) != sizeof(b));
>> + * BUILD_BUG_DECL(id_strings, ARRAY_SIZE(id_strings) != ARRAY_SIZE(id_vals));
>> + */
>> +#define BUILD_BUG_DECL(name, cond)                             \
>> +       static __initdata struct {                              \
>> +               int BUILD_BUG_DECL_ ## name[1 - 2*!!(cond)];    \
>> +       } BUILD_BUG_DECL_ ##name[0] __attribute__((unused))
>> +
>>
>> It lets you check array consistency at compile-time,
>> rather than waiting til run-time.
>
> I don't see how this is an improvement over BUILD_BUG_ON() which
> does the same thing.
>

almost the same thing.

BUILD_BUG_ON()  has a do {} while ( at least when __OPTIMIZE__ is
true), so it cant be used at file-scope,
ie outside of function bodies.


> regards,
> dan carpenter
>
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux