From: Vitaly Cheptsov via Groups.Io Date: Fri, 16 Aug 2019 23:28:14 +0000 (+0800) Subject: MdePkg: Add STATIC_ASSERT macro X-Git-Tag: edk2-stable201911~281 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=204ae9da230ecbf0910c21acac7aa5d5e8cbb8d0 MdePkg: Add STATIC_ASSERT macro 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 Reviewed-by: Philippe Mathieu-Daude Reviewed-by: Michael Kinney Reviewed-by: Jiewen Yao Acked-by: Jiewen Yao --- diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index ce20b5f01d..ec096133ba 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -843,6 +843,20 @@ typedef UINTN *BASE_LIST; #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field)) #endif +/** + Portable definition for compile time assertions. + Equivalent to C11 static_assert macro from assert.h. + + @param Expression Boolean expression. + @param Message Raised compiler diagnostic message when expression is false. + +**/ +#ifdef _MSC_EXTENSIONS + #define STATIC_ASSERT static_assert +#else + #define STATIC_ASSERT _Static_assert +#endif + /** Macro that returns a pointer to the data structure that contains a specified field of that data structure. This is a lightweight method to hide information by placing a