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