* modules/verify: New file.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 22 Sep 2005 22:56:28 +0000 (22:56 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 22 Sep 2005 22:56:28 +0000 (22:56 +0000)
* lib/verify.h: New file.
* MODULES.html.sh (Diagnostics <assert.h>): New section,
with "verify" module.

MODULES.html.sh
lib/verify.h [new file with mode: 0644]
modules/verify [new file with mode: 0644]

index 534a3e7..72dfecd 100755 (executable)
@@ -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
diff --git a/lib/verify.h b/lib/verify.h
new file mode 100644 (file)
index 0000000..c755762
--- /dev/null
@@ -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 (file)
index 0000000..6bb02b8
--- /dev/null
@@ -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