"错: void 值不被忽略,因为预期"解决
在C陷阱与缺陷,实现assert什么时候,在这个过程很聪明,化为一个表达式,在当条件为假时就会调用_assert_error报错并终止程序。
刚開始_assert_error 的返回值类型是 void 所以在((void)((e)
|| _assert_error(__FILE__, __LINE__))) 中出现了错误:void 值未如预期地被忽略,尽管exit(-1)并不会强制要求函数的返回值类型,可是由于_assert_error參与的是逻辑表达式计算,须要返回值。所以没有返回值的逻辑
本身就错的,更别说最后忽略返回值类型(在进行void强制忽略的时候就会察觉到这里的异常)。
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4
5 #define assert(e) \
6 ((void)((e) || _assert_error(__FILE__, __LINE__)))
7 // { if(!(e)) assert_error(__FILE__, __LINE__); }
8
9 int _assert_error(char *filename, int line){
10 printf("Error ouccurred in %s at line:%d\n", filename, line);
11 exit(-1);
12 }
13
14
15 int main(){
16 int flag = 1;
17 int y = -8;
18 if(flag)
19 assert(y > 0);
20 else printf("hhhhhhhhh\n");
21 printf("%f\n", sqrt(y));
22 // printf("test, %s--%d\n", __FILE__, __LINE__);
23
24 return 0;
25 }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
"错: void 值不被忽略,因为预期"解决的更多相关文章
- gorm 更新数据时,0值会被忽略
原文: https://www.tizi365.com/archives/22.html ------------------------------------------------------- ...
- 抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法
抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法 原因是https证书问题, ...
- flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法
flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...
- 关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法
关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法 近期在评估使用NIOS II处理器进行项目的 ...
- CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法
CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法 报错 #10008-D cann ...
- 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法
pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...
- windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决
windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决 一.发现问题 由于tomcat内存溢出,在wind ...
- 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:
使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...
- python mysqldb 报错: ProgrammingError: must be real number, not str 解决
代码: sql = 'insert into book(book_name,book_desc,origin_price,publish_id,tag_id,book_img) values(%s,% ...
随机推荐
- iis虚拟目录引发的路径问题
在iis上把web程序配置成站点是ok的,但配置成虚拟目录,就会发现 图片路径不能,样式不能加载,链接出错. 解决方案: 1,上传图片 ~/upload 2,cs程序,链接跳转,请用~/index. ...
- Android运用自己的标题栏
Android程序的标题栏TitleBar区域很单调,如果想个性化一些可以通过下面的方法来为自己软件的标题定制一个layout布局文件,比如浏览器的标题栏,它包含了网站的Favicon,自定义的进度条 ...
- $.ajax通路RESTful Web Service一个错误:Unsupported Media Type
最近项目,使用头版jquery ajax访问背景CXF发布时间rest维修,结果遇到了错误"Unsupported Media Type". 公布的服务java代码例如以下: im ...
- Ubuntu14.04下安装ZendStudio10.6.1+SVN出现Failed to load JavaHL Library
Subclipse不能正常工作,打开后报错: Failed to load JavaHL Library. These are the errors that were encountered: no ...
- 卓尼斯ZT-180点评
卓尼斯ZT-180点评 ——我们出差,使用10”上网本发布,没有图片.并写冲忙.遗憾的不足之处. 一.购买 1.由于旅游.不想拿那台14"笔记本,台平板电脑.当时,选择的对象有维智A8 ...
- fzu 2150 Fire Game 【身手BFS】
称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...
- ZOJ 3795 Grouping(Tarjan收缩点+DAG)
Suppose there are N people in ZJU, whose ages are unknown. We have some messages about them. The i-t ...
- SQLServer 2008 技术内幕——T-SQL 查询 笔记
原文:SQLServer 2008 技术内幕--T-SQL 查询 笔记 1.SQL编程有许多独特之处,如:面向集合的思维方式.查询元素的逻辑处理顺序.三值逻辑.如果不掌握这些知识就开始用SQL编程,得 ...
- Big ball of Mud
Big ball of Mud 第一种死法:Big ball of Mud 架构里最常用的反面案例是 big ball of mud.很大程度上可以说打格子,把复杂的系统拆解成小格子是架构师最重要的工 ...
- Sonar Qube QA
配置:1.配置环境变量 SONAR_RUNNER_HOME2.配置path :增加%SONAR_RUNNER_HOME%\bin3.在自己的本地项目的根目录下创建 sonar-project.pro ...