Re: Type-generic macros with C

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

 



> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux