exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / assure.h
blobd650ca15366ffe57d6d6060c2f078b262f4c983b
1 /* Run-time assert-like macros.
3 Copyright (C) 2014-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Paul Eggert. */
20 #ifndef _GL_ASSURE_H
21 #define _GL_ASSURE_H
23 #include <assert.h>
24 #include "verify.h"
26 /* Evaluate an assertion E that is guaranteed to be true.
27 If NDEBUG is not defined, abort the program if E is false.
28 If NDEBUG is defined, the compiler can assume E and behavior is
29 undefined if E is false, fails to evaluate, or has side effects.
31 Unlike standard 'assert', this macro evaluates E even when NDEBUG
32 is defined, so as to catch typos, avoid some GCC warnings, and
33 improve performance when E is simple enough.
35 Also see the documentation for 'assume' in verify.h. */
37 #ifdef NDEBUG
38 # define affirm(E) assume (E)
39 #else
40 # define affirm(E) assert (E)
41 #endif
43 /* Check E's value at runtime, and report an error and abort if not.
44 However, do nothing if NDEBUG is defined.
46 Unlike standard 'assert', this macro compiles E even when NDEBUG
47 is defined, so as to catch typos and avoid some GCC warnings.
48 Unlike 'affirm', it is OK for E to use hard-to-optimize features,
49 since E is not executed if NDEBUG is defined. */
51 #ifdef NDEBUG
52 # define assure(E) ((void) (0 && (E)))
53 #else
54 # define assure(E) assert (E)
55 #endif
57 #endif