"错: 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,% ...
随机推荐
- UIScrollViewA都PI得知。
//1.设定滚定条的样式 typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) { UIScrollViewIndicatorStyleDefa ...
- Vim设置colorscheme小技巧
Vim的颜色主题在/usr/share/vim/vim73/colors目录里.打开vim后在normal模式下输入":colorscheme"查看当前的主题,改动主题使用命令&q ...
- Oracle基于学习3--Oracle创建用户和授权
Oracleserver端的操作,如以下一般: 1) 安装Oracleserver软件 2) 创建数据库(安装时自己主动创建) 3) 配置监听(安装时自己主动配置) ...
- EmEditor Professional(文本编辑) 下载地址
http://www.greenxf.com/soft/2126.html 16.1.5 http://www.cr173.com/soft/3031.html 16.3.0
- 如何插上U盘 自动复制内容
U盘插入自动复制,有效对付那些不肯给PPT的老师,还有一定几率拿到期末考试卷子···有图有真相!业界良心的好东西!!现在看还来得及!!! 代码优化了一下,把不是很重要的都删掉了,这次使用时看不出任何现 ...
- org.apache.jasper.JasperException: An exception occurred processing JSP page /admin/jiaoshi/daochuEx
org.apache.jasper.JasperException: An exception occurred processing JSP page /admin/jiaoshi/daochuEx ...
- JavaFX横幅类游戏开发 教训 游戏贴图
上一节课,我们即将完成战旗Demo有了一个大概的了解.教训这,我们将学习绘制游戏地图. 由于JavaFX 2.2中添加了Canvas相关的功能,我们就能够使用Canvas来实现游戏绘制了. 游戏地图绘 ...
- SDUTOJ 1298 活动选择
#include<iostream> #include<memory.h> using namespace std; int a[105],b[105],c[105],d[10 ...
- ubuntu 下搭建apache+python的运行环境
ubuntu下怎么搭建apache+python运行环境,可以参考http://www.01happy.com/ubuntu-apache-mod-python/ ,这里只是简单的记录下步骤,本文主要 ...
- 使用autoconf和automake生成Makefile文件(转)
Makefile好难写 曾经也总结了一篇关于Makefile的文章<make和makefile的简单学习>.但是,总结完以后,发现写Makefile真的是一件非常痛苦的事情,的确非常痛苦. ...