xref: /freebsd/share/man/man3/unreachable.3 (revision 233ddc56a7ed222ea8903479cd3ae9df044b990a)
1.\"
2.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd November 27, 2025
7.Dt UNREACHABLE 3
8.Os
9.Sh NAME
10.Nm unreachable
11.Nd the unreachable macro
12.Sh SYNOPSIS
13.In stddef.h
14.Fd #define unreachable()
15.Sh DESCRIPTION
16If the
17.Fn unreachable
18macro is reached during execution, behavior is undefined.
19This can be useful to hint to the compiler that some invariant is guaranteed to
20hold or that some case cannot occur.
21.Sh EXAMPLES
22Suppose a floating-point number
23.Va x
24is to be classified using the
25.Xr fpclassify 3
26macro and a different action is to be taken based on the result of the
27classification.
28As the set of possible return values is known, the
29.Fn unreachable
30macro can be used to hint to the compiler that it can omit checks for
31other possible return values:
32.Bd -literal -offset 3n
33#include <math.h>
34#include <stddef.h>
35#include <stdio.h>
36
37void print_classification(double x)
38{
39	printf("%f: ", x);
40
41	switch (fpclassify(x)) {
42	case FP_INFINITE:
43		puts("infinite");
44		break;
45
46	case FP_NAN:
47		puts("not a number");
48		break;
49
50	case FP_NORMAL:
51		puts("normal");
52		break;
53
54	case FP_SUBNORMAL:
55		puts("subnormal");
56		break;
57
58	case FP_ZERO:
59		puts("zero");
60		break;
61
62	default:
63		unreachable();
64	}
65}
66.Ed
67.Sh SEE ALSO
68.Xr assert 3
69.Sh STANDARDS
70The
71.Fn unreachable
72macro conforms to
73.St -isoC-2023 .
74.Sh HISTORY
75A
76.Dv /*NOTREACHED*/
77conventional comment was supported by the historical
78.Xr lint 1
79utility to suppress warnings about unreachable statements during static
80analysis.
81The
82.Fn unreachable
83macro was added in
84.Fx 15.1
85based on the earlier private
86.Fn __unreachable
87macro for compliance with
88.St -isoC-2023 .
89.Sh AUTHOR
90.Ah Robert Clausecker Aq Mt fuz@FreeBSD.org
91