I'm starting to import gnulib changes from coreutils. The first step is to add a new module "verify", which defines macros verify(EXPR) and verify_expr(EXPR) that act like assert(EXPR) except they check EXPR at compile-time, not at run-time. verify(EXPR) is for declaration contexts, and verify_expr is for expression contexts.
Here's the patch I just installed: 2005-09-22 Paul Eggert <[EMAIL PROTECTED]> * MODULES.html.sh (Diagnostics <assert.h>): New section, with "verify" module. * modules/verify: New file. * lib/verify.h: New file. Index: MODULES.html.sh =================================================================== RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v retrieving revision 1.107 diff -p -u -r1.107 MODULES.html.sh --- MODULES.html.sh 16 Sep 2005 06:52:14 -0000 1.107 +++ MODULES.html.sh 22 Sep 2005 22:54:16 -0000 @@ -1424,6 +1424,16 @@ func_all_modules () func_wrap H2 func_echo "$element" + element="Diagnostics <assert.h>" + 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 <stdlib.h>" element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"` func_section_wrap ansic_enh_stdlib_memory --- /dev/null 2005-06-27 15:40:05.000000000 -0700 +++ modules/verify 2005-09-20 22:51:57.000000000 -0700 @@ -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 --- /dev/null 2005-06-27 15:40:05.000000000 -0700 +++ lib/verify.h 2005-09-20 22:36:37.000000000 -0700 @@ -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 _______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib