[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] include/essentials.h: introduce compile-time assert



Macro UK_CTASSERT(cond) is borrowed from FreeBSD. If 'cond' is False,
compilation is aborted with message "size of array is negative". Even
though the message is not very helpful, it is the simplest workaround
to have compile-time assertion without enabling c11 standard.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 include/uk/essentials.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/uk/essentials.h b/include/uk/essentials.h
index d9b24fcb..2cbb6aef 100644
--- a/include/uk/essentials.h
+++ b/include/uk/essentials.h
@@ -250,6 +250,13 @@ extern "C" {
 #endif
 #endif /* !__containerof */
 
+#ifndef UK_CTASSERT
+#define UK_CTASSERT(x)             _UK_CTASSERT(x, __LINE__)
+#define _UK_CTASSERT(x, y)         __UK_CTASSERT(x, y)
+#define __UK_CTASSERT(x, y)        typedef __maybe_unused \
+       char __assert_ ## y [(x) ? 1 : -1]
+#endif /* UK_CTASSERT */
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.19.2


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.