* verify.h (GL_CONCAT0, GL_CONCAT): Define unconditionally; don't
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Jul 2005 05:16:08 +0000 (05:16 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Jul 2005 05:16:08 +0000 (05:16 +0000)
depend on whether verify_decl is defined.
(verify): Renamed from verify_decl.  All uses changed.
Use an extern function decl, as it can't possibly collide with other
decls.
(verify_expr): Renamed from verify.  All uses changed.
(verify_type__): New private macro.
(verify, verify_expr): Use it.

lib/verify.h

index b86acae..7880526 100644 (file)
    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
 
-# ifndef verify_decl
-#  define GL_CONCAT0(x, y) x##y
-#  define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
-
-/* Verify requirement, R, at compile-time, as a declaration.
-   The implementation uses a struct declaration whose name includes the
-   expansion of __LINE__, so there is a small chance that two uses of
-   verify_decl from different files will end up colliding (for example,
-   f.c includes f.h and verify_decl is used on the same line in each).  */
-#  define verify_decl(R) \
-    struct GL_CONCAT (ct_assert_, __LINE__) { char a[(R) ? 1 : -1]; }
-# endif
-
-/* Verify requirement, R, at compile-time, as an expression.
-   Unlike assert, there is no run-time overhead.  Unlike verify_decl,
-   above, there is no risk of collision, since there is no declared name.
-   This macro may be used in some contexts where the other may not, and
-   vice versa.  Return void.  */
-# undef verify
-# define verify(R) ((void) sizeof (struct { char a[(R) ? 1 : -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 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) sizeof (verify_type__ (R)))
 
 #endif