"错: 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,% ...
随机推荐
- 北邮iptv用WindowsMediaplayer打不开的解决的方法
前言:之前我的iptv能够用,可是有次我安装了realplayer,它就偷偷把iptv文件的默认打开方式给篡改了,卸载了 realplayer之后,iptv不能直接用 ...
- tolower (Function)
this is a function that Convert uppercase letter to lowercase Converts c to its lowercase equivalent ...
- 乐在其中设计模式(C#) - 迭代器模式(Iterator Pattern)
原文:乐在其中设计模式(C#) - 迭代器模式(Iterator Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 迭代器模式(Iterator Pattern) 作者:weba ...
- Lua 数据库访问(转)
本文主要为大家介绍 Lua 数据库的操作库:LuaSQL.他是开源的,支持的数据库有:ODBC, ADO, Oracle, MySQL, SQLite 和 PostgreSQL. 本文为大家介绍MyS ...
- java Double保留小数点位数
0和#都是占位符,但在不同的地方,作用不一样0: 比实际数字的位数多,不足的地方用0补上. new DecimalFormat("00.00").format(3.14) //结果 ...
- NYOJ 745 蚂蚁问题(两)
蚂蚁的难题(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 下雨了,下雨了.蚂蚁搬家了. 已知有n种食材须要搬走,这些食材从1到n依次排成了一个圈.小蚂蚁对每种 ...
- BZOJ 3236 AHOI 2013 作业 莫队算法
题目大意:给出一些数,问在一个区间中不同的数值有多少种,和在一个区间中不同的数值有多少个. 思路:因为没有改动,所以就想到了莫队算法.然后我写了5K+的曼哈顿距离最小生成树,然后果断T了.(100s的 ...
- IBatis增删改差的实现以及注意点
此次进讲述对表操作的实现细节.废话不多说,代码见真章. <?xml version="1.0" encoding="utf-8" ?> <sq ...
- C语言标准库函数qsort具体解释
1 函数简单介绍 功 能: 使用高速排序例程进行排序 头文件:stdlib.h 用 法: void qsort(void *base,int nelem,int width,int (*fcmp)(c ...
- SharePoint使用BCS开发你第一个应用程序(三)
SharePoint使用BCS开发你第一个应用程序(三) 创建外部内容类型. 创建外部内容类型有三种不同方式: 1. 在记事本上手写XML代码(不推荐). 2. 使用SharePoin ...