This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Type-generic macros with C


> 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.

The code

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.

Joerg



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]