Skip to content

Is

Description

Predicate: does the static type of x exactly equal type T?

Usage example (from documentation)

  if (Is(x, int)) { ... }

Success

Expands to the integer constant 1 if TYPE_OF(x) is T, otherwise 0. The result is a _Generic constant, usable in any constant context and folded away by the optimiser.

Failure

Macro cannot fail. T must name a single complete type token.

Usage example (Cross-references)

Usage examples (Cross-references)
    #ifdef EISDIR
            case EISDIR :
                return "Is a directory";
    #endif
    #ifdef EINVAL
        int    i = 0;
        double d = 0.0;
        return Is(i, int) == 1 && Is(i, double) == 0 && Is(d, double) == 1 && Is(d, int) == 0;
    }
    /* static arm: it = the value (its static type). */
    #define When_1(T)                                                                                                      \
        if (!MisraMatched && Is(MisraSubject, T) && (MisraMatched = true))                                                 \
            for (TYPE_OF(MisraSubject) it = MisraSubject, *UNPL(tm_bind) = ⁢ UNPL(tm_bind); UNPL(tm_bind) = NULL)
Last updated on