码迷,mamicode.com
首页 > 其他好文 > 详细

micro assert 宏assert()

时间:2017-10-15 19:30:15      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:__file__   void   ogr   system   head   fine   eth   dia   cond   

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
引用自百度百科

micro assert 宏assert()

标签:__file__   void   ogr   system   head   fine   eth   dia   cond   

原文地址:http://www.cnblogs.com/1915884031A-qqcom/p/7672781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!