]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Add STATIC_ASSERT macro
authorVitaly Cheptsov via Groups.Io <vit9696=protonmail.com@groups.io>
Fri, 16 Aug 2019 23:28:14 +0000 (07:28 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 11 Sep 2019 14:30:16 +0000 (22:30 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2048

Provide a macro for compile time assertions.
Equivalent to C11 static_assert macro from assert.h.

Signed-off-by: Vitaly Cheptsov <vit9696@protonmail.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
MdePkg/Include/Base.h

index ce20b5f01dce453b8f246e28b2a297103b03439c..ec096133baafd40a17afc97bddc674af88e63b55 100644 (file)
@@ -843,6 +843,20 @@ typedef UINTN  *BASE_LIST;
 #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))\r
 #endif\r
 \r
+/**\r
+  Portable definition for compile time assertions.\r
+  Equivalent to C11 static_assert macro from assert.h.\r
+\r
+  @param  Expression  Boolean expression.\r
+  @param  Message     Raised compiler diagnostic message when expression is false.\r
+\r
+**/\r
+#ifdef _MSC_EXTENSIONS\r
+  #define STATIC_ASSERT static_assert\r
+#else\r
+  #define STATIC_ASSERT _Static_assert\r
+#endif\r
+\r
 /**\r
   Macro that returns a pointer to the data structure that contains a specified field of\r
   that data structure.  This is a lightweight method to hide information by placing a\r