dylancao

  断言函数的格式如下所示:

  void assert (int expression);
如果参数expression等于零,一个错误消息将会写入到设备的标准错误集并且会调用abort函数,就会结束程序的执行。
  断言的消息会显示库依赖,但是它也包含一下信息,源文件的名字,处于哪一行,在哪儿发生的,一般的格式如下:
Assertion failed: expression, file filename, line line number
该函数的头文件如下所示:
  <assert.h>

  该函数的源码应用如下所示:

 1 /* assert example */
 2 #include <stdio.h>      /* printf */
 3 #include <assert.h>     /* assert */
 4 
 5 void print_number(int* myInt) {
 6   assert (myInt!=NULL);
 7   printf ("%d\n",*myInt);
 8 }
 9 
10 int main ()
11 {
12   int a=10;
13   int * b = NULL;
14   int * c = NULL;
15 
16   b=&a;
17 
18   print_number (b);
19   print_number (c);
20 
21   return 0;
22 }

 参考文档:

1 http://www.cplusplus.com/reference/cassert/assert/

分类:

技术点:

相关文章:

  • 2021-06-29
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-01-12
  • 2021-12-28
相关资源
相似解决方案