assert的用法

来源:互联网 发布:idc 大型网络架构 编辑:程序博客网 时间:2024/05/06 10:15

函数名: assert
功  能: 测试一个条件并可能使程序终止
用  法: void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

struct ITEM {
   int key;
   int value;
};

/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
   assert(itemptr != NULL);
   /* add item to list */
}

int main(void)
{
   additem(NULL);
   return 0;
}

原创粉丝点击