Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1283659
| From | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits |
| Date | 2015-12-04 10:10 +0100 |
| Message-ID | <qBUxj-Hj-7@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <qBJ8T-1Cs-51@gated-at.bofh.it> <qBJ8T-1Cs-49@gated-at.bofh.it> <qBJLA-25s-23@gated-at.bofh.it> <qBLDI-3fK-13@gated-at.bofh.it> <qBM6K-3He-15@gated-at.bofh.it> |
| Organization | D03 |
On Fri, Dec 04 2015, Joe Perches <joe@perches.com> wrote: > On Thu, 2015-12-03 at 15:34 -0800, Andrew Morton wrote: >> I've been fiddling with a BUILD_BUG_ON which works outside functions >> using gcc's __COUNTER__ - something like >> >> #define BBO(expr) typedef char __bbo##__COUNTER__[1-2*(!!expr)] > > nit: you need another parenthesis around expr > >> BBO(1 == 1); >> BBO(2 == 2); >> >> but that comes out as >> >> typedef char __bbo__COUNTER__[1-2*(!!1 == 1)]; >> typedef char __bbo__COUNTER__[1-2*(!!2 == 2)]; >> >> instead of >> >> typedef char __bbo0[1-2*(!!1 == 1)]; >> typedef char __bbo1[1-2*(!!2 == 2)]; >> >> There's some trick here but I've forgotten what it is. > > I believe it's something like: > > #define __stringify_2(a, b) a##b > #define __stringify2(a, b) __stringify_2(a, b) > > #define BBO(expr) typedef char __stringify2(bbo, __COUNTER__)[1 - 2*(!!(expr))] Let's at least not reinvent two wheels. __UNIQUE_ID exists and does the gluing (which we have __PASTE for, not stringify) etc., and uses __LINE__ as a poor man's fallback for compilers without __COUNTER__ (gcc < 4.3). But I don't see why we even need the unique identifier. What's wrong with 'extern char blabla[1 - 2*(!!(expr))]'? blabla can be declared multiple times without problems - and when it fails, we either get a 'negative size' error or at least some complaint about conflicting declarations. Maybe stick a __always_unused in to prevent gcc from complaining if this declaration is inside a function. Rasmus -- 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/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 00/14] printf stuff for 4.5 Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 01/14] lib/vsprintf.c: pull out padding code from dentry_name() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Joe Perches <joe@perches.com> - 2015-12-03 22:00 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-03 22:40 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Andrew Morton <akpm@linux-foundation.org> - 2015-12-04 00:40 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Joe Perches <joe@perches.com> - 2015-12-04 01:10 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-04 10:10 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-04 10:10 +0100
Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Joe Perches <joe@perches.com> - 2015-12-04 00:50 +0100
[PATCH v3 08/14] lib/test_printf.c: don't BUG Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 03/14] lib/vsprintf.c: eliminate potential race in string() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 06/14] lib/vsprintf.c: warn about too large precisions and field widths Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 09/14] lib/test_printf.c: check for out-of-bound writes Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 02/14] lib/vsprintf.c: move string() below widen_string() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
[PATCH v3 14/14] lib/test_printf.c: test dentry printing Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
Re: [PATCH v3 14/14] lib/test_printf.c: test dentry printing Andrew Morton <akpm@linux-foundation.org> - 2015-12-04 01:20 +0100
Re: [PATCH v3 14/14] lib/test_printf.c: test dentry printing Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-04 09:20 +0100
Re: [PATCH v3 14/14] lib/test_printf.c: test dentry printing Andrew Morton <akpm@linux-foundation.org> - 2015-12-04 09:50 +0100
[PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-03 22:00 +0100
csiph-web