To create functions which can take two types, but still warn on any other types, we need a way of casting one type and no others. To make things more complex, it should correctly handle function args, NULL, and be usable in initializers. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> diff -r e6626cc7bdc2 include/linux/compiler-gcc.h --- a/include/linux/compiler-gcc.h Sun Jan 20 18:51:51 2008 +1100 +++ b/include/linux/compiler-gcc.h Sun Jan 20 18:57:14 2008 +1100 @@ -53,3 +53,20 @@ #define noinline __attribute__((noinline)) #define __attribute_const__ __attribute__((__const__)) #define __maybe_unused __attribute__((unused)) + +/** + * cast_if_type - allow an alternate type + * @expr: the expression to optionally cast + * @oktype: the type to allow. + * @desttype: the type to cast to. + * + * This is used to accept a particular alternate type for an expression: + * because any other types will not be cast, they will cause a warning as + * normal. + * + * Note that the unnecessary trinary forces functions to devolve into + * function pointers as users expect. */ +#define cast_if_type(expr, oktype, desttype) \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(1?(expr):NULL), \ + oktype), \ + (desttype)(expr), (expr)) diff -r e6626cc7bdc2 include/linux/compiler-intel.h --- a/include/linux/compiler-intel.h Sun Jan 20 18:51:51 2008 +1100 +++ b/include/linux/compiler-intel.h Sun Jan 20 18:57:14 2008 +1100 @@ -29,3 +29,5 @@ #endif #define uninitialized_var(x) x + +#define cast_if_type(expr, oktype, desttype) ((desttype)(expr)) --
| H. Peter Anvin | Re: [RFC 00/15] x86_64: Optimize percpu accesses |
| Linus Torvalds | Linux 2.6.27-rc5 |
| Ingo Molnar | [announce] "kill the Big Kernel Lock (BKL)" tree |
| Greg KH | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
git: | |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| Ben Hutchings | Re: [GIT]: Networking |
| Jarek Poplawski | [PATCH iproute2] Re: HTB accuracy for high speed |
