P99

◆ P99_GEN_EXPR
Produce a type generic expression that can be used as if it were an The motivation for declaring a macro that uses this is for expressions that evaluate their arguments multiple times. E.g to define a macro P99_GEN_MAX you can use the following P99_DECLARE_INLINE_EXPRESSIONS((maximum,
(p00_a >= p00_b) ? p00_a : p00_b,
p00_a, p00_b),
b, c, hh, uhh, h, uh, i, u, l, ul, ll, ull,
);
#define P99_GEN_MAX(A, B) \
P99_GEN_EXPR(maximum, ((A) >= (B)) ? (A) : (B), \
b, c, hh, uhh, h, uh, i, u, l, ul, ll, ull, \
d, f, ld \
) \
((A), (B))
This first defines 15 inline functions for the different arithmetic types, you could also just use P99_STD_ARITHMETIC_EXTS to produce that long list. Then the definition of the macro expands to a type generic expression that has as EXPR as its selection expression (here
So, staying with the example above, we would have the commonly used type of As you can already see from this simple example, for such an expression it is crucial that Here is another example that shows how simple it is to produce the type generic math macros that should normally be provided by "tgmath.h". #define p00_gen_sind sin
#define p00_gen_sinf sinf
#define p00_gen_sinld sinl
#define p00_gen_sindc csin
#define p00_gen_sinfc csinf
#define p00_gen_sinldc csinl
#define P99_GEN_SIN(A) P99_GEN_EXPR(sin, (A), P99_STD_FLOATING_EXTS)(A)
Definition at line 1000 of file p99_generic.h. 