android 中CHECK宏分析

本文详细分析了Android中CHECK宏的实现与作用,指出其不仅在debug版本,也在release版本中运行并可能导致程序退出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看到CHECK宏,开始以为和ASSERT一样,在release中不起作用。实际上是起作用的,会引起退出。下面是具体的源代码分析

 32 #define CHECK(condition)                                \
 33     LOG_ALWAYS_FATAL_IF(                                \
 34             !(condition),                               \
 35             "%s",                                       \
 36             __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
 37             " CHECK(" #condition ") failed.")


302 /*
303  * Log a fatal error.  If the given condition fails, this stops program
304  * execution like a normal assertion, but also generating the given message.
305  * It is NOT stripped from release builds.  Note that the condition test
306  * is -inverted- from the normal assert() semantics.
307  */
308 #ifndef LOG_ALWAYS_FATAL_IF
309 #define LOG_ALWAYS_FATAL_IF(cond, ...) \
310     ( (CONDITION(cond)) \
311     ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值