"错: 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,% ...
随机推荐
- Lua相关的知识
http://stackoverflow.com/questions/5438751/how-to-debug-lua-remotely http://cn.bing.com/search?q=org ...
- CentOS 6.3 安装 samba 共享(转)
PHP环境在linux下,但是开发的时候用的是windows,于是我用了samba将linux的一个目录共享,然后在windows上做映射,这样就可以直接在windows下编辑linux上的文件了 首 ...
- 最短路径:Dijkstra,Bellman,SPFA,Floyd该算法的实施
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQ4NzA1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- JavaScript的"类"
1. 基本创建“类”方式 var Class = function(){ var klass = function(){ this.init.apply(this, arguments); }; kl ...
- linuxc_螺纹锁紧pthread_mutex_t
在实际执行过程中的线程,我们经常需要同步多线程. 然后你可以使用互斥锁来完成任务:在使用过程中互斥锁,有pthread_mutex_init,pthread_mutex_destory,pthread ...
- Windows Server 2012启用Windows功能NetFx3时出错解决方法
作者:冰点阳光 | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址:http://baohua.me/operating-system/windows-server-2012- ...
- role 'PLUSTRACE' does not exist
I have created a new user named watson and granted the related priviledges as following: SQL> cre ...
- DOM笔记2
<!-- 节点类型检查 if(someNode.nodeType==ElementNode){ alert("Node is an element"); } 或者 if(so ...
- c#左右socket连接超时控制方案
之前有一个项目中使用Remoting技术.当远程地址无效或server不执行,访问远程对象的方法,它会经过几十秒的时间来抛出异常秒. 由于我使用tcp状态.因此,认为可以使用socket为了测试连接, ...
- Cocos2d-x 2.2.3 Android配置
今天总结出来的部署流程,已经成功把自己的项目编译到android真机上.省去了安装ndk等步骤 环境: win7 64位 1.导入项目到eclipse 2.导入libcocos2dx 样例:C:\co ...