在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 }

版权声明:本文博客原创文章,博客,未经同意,不得转载。

&quot;错: void 值不被忽略,因为预期&quot;解决的更多相关文章

  1. gorm 更新数据时,0值会被忽略

    原文: https://www.tizi365.com/archives/22.html ------------------------------------------------------- ...

  2. 抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法

    抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法 原因是https证书问题, ...

  3. flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法

    flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...

  4. 关于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处理器进行项目的 ...

  5. CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法

    CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法 报错 #10008-D cann ...

  6. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  7. 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 ...

  8. 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:

     使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...

  9. 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,% ...

随机推荐

  1. hdu 4864 Task (馋)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  2. synchronized与static synchronized 差异

    1.synchronized与static synchronized 差异       synchronized是对类的当前实例进行加锁,防止其它线程同一时候訪问该类的该实例的全部synchroniz ...

  3. Intel® Ethernet Connection I217-V 网卡驱动(win10 ,2012)

    https://downloadcenter.intel.com/zh-cn/download/25016/-Windows-10 上面是win10 的驱动 win8.1  https://downl ...

  4. cassandra 服务启动流程

    cassandra 服务启动流程 1.  setup 1)   CassandraDaemon ->main publicstaticvoidmain(String[]args) { insta ...

  5. AutoMapper在ABP框架

    AutoMapper在ABP框架中的使用说明 为了说明AutoMapper如何使用,我专门开设了一个专题来讲,如果您还没有查看该专题,请点击这里.既然系统地学习了AutoMapper,那么接下来就是该 ...

  6. PHP获取表单方法

    php接收HTML当表单提交的信息,数据将存储提交在全局阵列中,我们能够调用系统特定的自己主动全局变量数组来获取这些值.经常使用的自己主动全局变量例如以下所看到的: $_GET $_POST $_RE ...

  7. webpack打包avalon

    webpack打包avalon+oniui+jquery 随着avalon的发展壮大,我根据CSDN的统计数字,中国前端大概有1%的人在使用avalon了. avalon的最大优势是能兼容IE6,并且 ...

  8. 也可以看看GCD(杭州电2504)(gcd)

    也可以看看GCD Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. A == B ?(杭州电2054)

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  10. Unity3d 导入图像尺寸失真解决方案

    导入到unity3d内的图像被默认长宽变换为满足2^n关系. 例如以下图,我有张图片名称为984plus598表示我尺寸为984*598.拷贝到unity3d中后的大小为1024*512 方法一: 在 ...