summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-07-04 16:05:41 +0000
committerJim Meyering <jim@meyering.net>2005-07-04 16:05:41 +0000
commitcfdfe3e3184657f1f414fef6054d2aba0e93badd (patch)
tree280a6505c0255865e918f714bcc3c7b914fd1734 /lib
parenta54b48abe6a657fee8317326b760a7702efb3333 (diff)
downloadcoreutils-cfdfe3e3184657f1f414fef6054d2aba0e93badd.tar.xz
(verify, verify_dcl): New file/macros.
Diffstat (limited to 'lib')
-rw-r--r--lib/verify.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/verify.h b/lib/verify.h
new file mode 100644
index 000000000..013ed84f8
--- /dev/null
+++ b/lib/verify.h
@@ -0,0 +1,43 @@
+/* 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. */
+
+#ifndef VERIFY_H
+# define VERIFY_H 1
+
+# ifndef verify_dcl
+# 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_dcl from different files will end up colliding (for example,
+ f.c includes f.h and verify_dcl is used on the same line in each). */
+# define verify_dcl(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_dcl,
+ 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]; }))
+
+#endif