mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
libnetbsd: import __CTASSERT(..) macros
These compile-time assert macros are similar to `Static_assert` on FreeBSD.
These macros are in use in newer versions of `contrib/netbsd-tests`.
Obtained from: https://github.com/NetBSD/src (c26cc77b3a0b26b95a2)
MFC after: 1 week
(cherry picked from commit d1f1402dff)
This commit is contained in:
1 parent
ee828a44e8
commit
7be895e500
1 file changed
+16
@@ -54,6 +54,22 @@
|
||||
#define ___STRING(x) __STRING(x)
|
||||
#define ___CONCAT(x,y) __CONCAT(x,y)
|
||||
|
||||
/*
|
||||
* Compile Time Assertion.
|
||||
*/
|
||||
#ifdef __COUNTER__
|
||||
#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__)
|
||||
#else
|
||||
#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__)
|
||||
#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \
|
||||
__CONCAT(_,b))
|
||||
#endif
|
||||
#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z)
|
||||
#define __CTASSERT1(x, y, z) \
|
||||
struct y ## z ## _struct { \
|
||||
unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \
|
||||
}
|
||||
|
||||
/*
|
||||
* The following macro is used to remove const cast-away warnings
|
||||
* from gcc -Wcast-qual; it should be used with caution because it
|
||||
|
||||
Reference in new issue
Block a user