xref: /dflybsd-src/contrib/grep/lib/assure.h (revision 91b9ed38d3db6a8a8ac5b66da1d43e6e331e259a)
1dc7c36e4SJohn Marino /* Run-time assert-like macros.
2dc7c36e4SJohn Marino 
3*09d4459fSDaniel Fojt    Copyright (C) 2014-2020 Free Software Foundation, Inc.
4dc7c36e4SJohn Marino 
5dc7c36e4SJohn Marino    This program is free software: you can redistribute it and/or modify
6dc7c36e4SJohn Marino    it under the terms of the GNU General Public License as published by
7dc7c36e4SJohn Marino    the Free Software Foundation; either version 3 of the License, or
8dc7c36e4SJohn Marino    (at your option) any later version.
9dc7c36e4SJohn Marino 
10dc7c36e4SJohn Marino    This program is distributed in the hope that it will be useful,
11dc7c36e4SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
12dc7c36e4SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13dc7c36e4SJohn Marino    GNU General Public License for more details.
14dc7c36e4SJohn Marino 
15dc7c36e4SJohn Marino    You should have received a copy of the GNU General Public License
16*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17dc7c36e4SJohn Marino 
18dc7c36e4SJohn Marino /* Written by Paul Eggert.  */
19dc7c36e4SJohn Marino 
20dc7c36e4SJohn Marino #ifndef _GL_ASSURE_H
21dc7c36e4SJohn Marino #define _GL_ASSURE_H
22dc7c36e4SJohn Marino 
23dc7c36e4SJohn Marino #include <assert.h>
24dc7c36e4SJohn Marino 
25dc7c36e4SJohn Marino /* Check E's value at runtime, and report an error and abort if not.
26*09d4459fSDaniel Fojt    However, do nothing if NDEBUG is defined.
27dc7c36e4SJohn Marino 
28dc7c36e4SJohn Marino    Unlike standard 'assert', this macro always compiles E even when NDEBUG
29dc7c36e4SJohn Marino    is defined, so as to catch typos and avoid some GCC warnings.  */
30dc7c36e4SJohn Marino 
31dc7c36e4SJohn Marino #ifdef NDEBUG
32dc7c36e4SJohn Marino # define assure(E) ((void) (0 && (E)))
33dc7c36e4SJohn Marino #else
34dc7c36e4SJohn Marino # define assure(E) assert (E)
35dc7c36e4SJohn Marino #endif
36dc7c36e4SJohn Marino 
37dc7c36e4SJohn Marino #endif
38