asserterror
时间: 2023-10-27 07:54:50 浏览: 38
assert函数是C语言中的一个有趣的函数,用于发现潜在的bug。它的作用是判断表达式的逻辑值,如果为假(为0),则会向stderr打印一条出错信息,并调用abort函数终止程序。如果为真,则什么也不做。assert函数的原型为void assert(int expression)。然而,频繁调用assert函数会影响程序的性能并增加额外开销。可以通过在#include <assert.h>的语句前插入#define NDEBUG来禁用或关闭assert函数。\[1\]
assert函数最常用的作用是检查bug。当你不希望出现某些结果时,可以利用assert函数进行检验。如果判断条件不满足,则会发出警告并停止程序运行。例如,可以使用assert函数来确保输入的值不为0。\[2\]
关于错误和异常,bug是指计算机程序中的缺陷,而debug是指发现并修正bug。错误是指结果和预期不一致的情况,可以分为设计实现错误和用户操作引起的错误。异常是在C++语言中引入的概念,在C语言中并不支持异常。编译错误是指不符合C语言基本语法要求的错误,运行错误是指非法操作,如被零除或读取非法内存,逻辑错误是指算法级或逻辑级的错误,如if语句中使用赋值操作符而不是相等操作符。\[3\]
#### 引用[.reference_title]
- *1* *2* *3* [C:assert()及error()的使用](https://blog.csdn.net/weixin_43429936/article/details/101511743)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)