设为首页 加入收藏

TOP

c标准函数库--->assert.h(三)
2013-07-22 18:00:57 】 浏览:1111
Tags:标准 函数 ---> assert.h

 

  [cpp]

  //定义NDEBUG

  #include<stdio.h>

  #include<stdlib.h>

  #define NDEBUG

  #include<assert.h>

  int main()

  {

  printf("1 ok hello \n");

  assert(1==4);;

  printf("2 ok exit \n");

  return 0;

  }

  [cpp]

  结果:

  ********************************

  1 ok hello

  2 ok exit

  ****************************************

  [cpp]

  原理:

  #define assert(test) if(!(test))\

  fprintf(stderr,"the failed : %s file %s ,line %i\n",#test, __FILE__,__LINE__);\

  abort();

  [cpp]

  模拟:

  #include<stdio.h>

  #include<stdlib.h>

  //#define NDEBUG

  //#include<assert.h>

  #define Assert(test) if(!(test)) fprintf(stderr,"Assertion failed: %s, file %s, line %i\n", #test, __FILE__, __LINE__);abort()

  int main()

  {

  printf("1 ok hello \n");

  Assert(1==4);

  printf("2 ok exit \n");

  return 0;

  }

  [cpp]

  结果:

  **************************************

  1 ok hello

  Assertion failed: 1==4, file assert_h_ex.c, line 9

  已放弃

      

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇c指针与地址 指针与函数 下一篇C语言中的序列点和副作用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目