# HG changeset patch # User Paul Eggert # Date 1127429788 0 # Node ID 58c87cabeb1c5b8c04ef6591f2f6036b06a40c60 # Parent 197ea79713239e6ef0f425acd6e8304bbd8a29e5 * modules/verify: New file. * lib/verify.h: New file. * MODULES.html.sh (Diagnostics ): New section, with "verify" module. diff --git a/MODULES.html.sh b/MODULES.html.sh --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1424,6 +1424,16 @@ func_wrap H2 func_echo "$element" + element="Diagnostics " + element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"` + func_section_wrap ansic_enh_assert_diagnostics + func_wrap H3 + func_echo "$element" + + func_begin_table + func_module verify + func_end_table + element="Memory management functions " element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"` func_section_wrap ansic_enh_stdlib_memory diff --git a/lib/verify.h b/lib/verify.h new file mode 100644 --- /dev/null +++ b/lib/verify.h @@ -0,0 +1,57 @@ +/* Compile-time assert-like macros. + + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert and Jim Meyering. */ + +#ifndef VERIFY_H +# define VERIFY_H 1 + +# define GL_CONCAT0(x, y) x##y +# define GL_CONCAT(x, y) GL_CONCAT0 (x, y) + +/* A type that is valid if and only if R is nonzero. + R should be an integer constant expression. + verify_type__ and verify_error_if_negative_size__ are symbols that + are private to this header file. */ + +# define verify_type__(R) \ + struct { int verify_error_if_negative_size__ : (R) ? 1 : -1; } + +/* Verify requirement R at compile-time, as a declaration. + R should be an integer constant expression. + Unlike assert, there is no run-time overhead. + + The implementation uses __LINE__ to lessen the probability of + generating a warning that verify_function_NNN is multiply declared. + However, even if two declarations in different files have the same + __LINE__, the multiple declarations are still valid C89 and C99 + code because they simply redeclare the same external function, so + no conforming compiler will reject them outright. */ + +# define verify(R) \ + extern verify_type__ (R) GL_CONCAT (verify_function_, __LINE__) (void) + +/* Verify requirement R at compile-time, as an expression. + R should be an integer constant expression. + Unlike assert, there is no run-time overhead. + This macro can be used in some contexts where verify cannot, and vice versa. + Return void. */ + +# define verify_expr(R) ((void) ((verify_type__ (R) *) 0)) + +#endif diff --git a/modules/verify b/modules/verify new file mode 100644 --- /dev/null +++ b/modules/verify @@ -0,0 +1,21 @@ +Description: +Compile-time assert-like macros. + +Files: +lib/verify.h + +Depends-on: + +configure.ac: + +Makefile.am: +lib_SOURCES += verify.h + +Include: +"verify.h" + +License: +GPL + +Maintainer: +Paul Eggert, Jim Meyering