micro assert 宏assert()

assert macro
Note: assert is a macro, not a function.in the c assert.h header file. the prototype of an assert macro is defined in <assert.h> and its effect is that if its condition return an false, the program execution is terminated, the prototype is defined:
#defineassert(expr)\
((expr)\
?__ASSERT_VOID_CAST(0)\
:__assert_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION))

/*DefinedInGlibc2.15*/ glibc is the libary which is issued by GNU
the role of assert is to calculate the expression, if its value is false(that is zero), then is will print out the contents of assert and __FILE__, __LINE,__ASSERT_FUNCTION, and then abort() function make kernel kill its coredump(whether to generate coredump files, depending on the system configuration);otherwhise,assert() has no effect, Macro assert() is generally used to confirm the normal operation of the program, the assert is true when the expression is true. after debug is complete, you do not have to move the assert() statement form the source code because the macro assert is defined as NULL when the macro NDEBUG is defined


它的作用是先计算表达式expr,如果其值为假(即为0),那么它会打印出来assert的内容和__FILE__, __LINE__, __ASSERT_FUNCTION,然后执行abort()函数使kernel杀掉自己并coredump(是否生成coredump文件,取决于系统配置);否则,assert()无任何作用。宏assert()一般用于确认程序的正常操作,其中表达式构造无错时才为真值。完成调试后,不必从源代码中删除assert()语句,因为宏NDEBUG有定义时,宏assert()的定义为空。[1]

quote from baidu encyclopedia
引用自百度百科

转载于:https://www.cnblogs.com/1915884031A-qqcom/p/7672781.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值