aimenfeifei

assert() 宏用法
注意:assert是宏,而不是函数。在C的assert.h头文件中。

#inlcude <assert.h>

用法:
void assert( int expression );
assert的作用是先计算表达式expression,如果其值为假(即为0),那么它先向标准错误流stderr打印一条出错信息,然后通过调用abort来终止程序运行;否则,assert()无任何作用。

例子:

void CLinkList::reverse()
{
PBINODE root = getroot();
assert(root != NULL);

PBINODE prenode = root->pnext;
assert(prenode != NULL);

PBINODE curnode = prenode->pnext;
prenode->pnext = NULL;
while (curnode != NULL)
{
PBINODE nextnode = curnode->pnext;
curnode->pnext = prenode;
prenode = curnode;
curnode = nextnode;
}

root->pnext = prenode;
}

分类:

技术点:

相关文章:

  • 2021-12-13
  • 2021-08-28
  • 2022-01-12
  • 2021-07-04
  • 2022-01-17
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2021-08-02
  • 2022-12-23
  • 2022-02-26
  • 2021-06-15
  • 2022-02-21
  • 2022-01-08
相关资源
相似解决方案