This is the mail archive of the
mailing list for the GCC project.
Re: Type-generic macros with C
- From: Jörg Leis <joerg at joergleis dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 30 Apr 2010 21:55:09 +0200
- Subject: Re: Type-generic macros with C
- References: <1272643259.4438.39.camel@maria> <email@example.com>
> My understanding is that __builtin_choose_expr does ignore the
> expression that is not chosen, so you must mean something other than I
> what mean. Please post an example.
void f_int(int *x);
void f_float(float *x);
#define is_int_ptr(x) __builtin_types_compatible_p((x),int *)
#define f(x) __builtin_choose_expr(is_int_ptr(x), f_int(x), f_float(x))
will warn about incompatible pointer types when called with a pointer to
an int and with a pointer to a float, although the chosen expression is
valid in either case. Moreover, it will warn about "dereferencing
type-punned pointer" when compiling with -O2.