如何让GCC ftrapv工作? [英] how to make gcc ftrapv work?

查看:1128
本文介绍了如何让GCC ftrapv工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译如下code作为

I am compiling the code below as

$ gcc -Wall  -ftrapv test.c

不过运行生成的可执行文件始终打印-2147483648这是不是我的预期。我运行gcc版本4.6.3(Ubuntu的/ Linaro的4.6.3-1ubuntu5)。

However running the generated executable always prints-2147483648 which is not what I expected. I am running gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5).

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <limits.h>
  4 #include <signal.h>
  5 
  6 void h(int signal)
  7 {
  8         printf("caught signal exiting\n");
  9         exit(1);
 10 }
 11 
 12 int main(void)
 13 {
 14         int x = INT_MAX;
 15         int y;
 16 
 17         signal(SIGABRT,h);
 18         y = x+1;
 19         printf("%d\n",y);
 20         return 0;
 21 }

后来补充:铿锵编译和改变SIGABRT到SIGILL作品,但用gcc至今没有运气

Added later: compiling with clang and changing SIGABRT to SIGILL works, but no luck with gcc so far.

推荐答案

看起来 -ftrapv 在海湾合作委员会的支持有​​所打破,他们有一个的开放的bug,从2008年在他们的Bugzilla错误-35412 似乎为了掩饰它。

It looks like -ftrapv support in GCC is somewhat broken, they have an open bug, Bug-35412 in their Bugzilla from 2008 it seems in order to cover it.

这篇关于如何让GCC ftrapv工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆