Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

unreachable — marking an unreachable path

The C23 unreachable macro marks a path execution must never reach. Reaching the invocation causes undefined behavior.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stddef.h>
/* Makro / macro: */
unreachable();

unreachable is a function-like macro from <stddef.h> in C23. The invocation unreachable() takes no arguments and expands to a void expression, not an ordinary function.

Reaching the invocation causes undefined behavior. It is neither validation nor guaranteed termination: the compiler may optimize code assuming that path is unreachable.

In the example, choose requires bit to be 0 or 1. The default branch expresses this requirement but does not check it safely. For external input, use error handling instead of unreachable().

Examples

#include <stddef.h>
#include <stdio.h>

#ifndef unreachable
#error "This example requires the C23 unreachable macro from <stddef.h>"
#endif

static int choose(unsigned int bit)
{
    switch (bit) {
    case 0: return 10;
    case 1: return 20;
    default: unreachable();
    }
}

int main(void)
{
    printf("%d %d\n", choose(0), choose(1));
    return 0;
}

Result

10 20

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources