new: 增加一些编译器相关的宏

This commit is contained in:
fslongjin
2022-10-05 21:40:03 +08:00
parent 7087e9fbc1
commit 9b37ff3e5a
7 changed files with 94 additions and 16 deletions

View File

@ -29,7 +29,7 @@
/**
* @brief 当condition不为0时输出警告信息且只会输出一次警告信息
*
*
*/
#define WARN_ON_ONCE(condition) ({ \
static int __warned; \
@ -49,4 +49,20 @@
goto to; \
unlikely(__ret_warn_on); \
})
/**
* @brief 当condition为true时中断编译并输出错误信息msg
*
* 如果你的代码依赖于一些能够在编译期间计算出来的值,那么请使用这个宏以防止其他人错误的修改了这些值,从而导致程序运行错误
*/
#define BUILD_BUG_ON_MSG(condition, msg) complietime_assert(!(condition), msg)
/**
* @brief 当condition为true时中断编译。
*
* 如果你的代码依赖于一些能够在编译期间计算出来的值,那么请使用这个宏以防止其他人错误的修改了这些值,从而导致程序运行错误
*/
#define BUILD_BUG_ON(condition) \
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
#pragma GCC pop_options