与__int128_t在Clang中的错误? [英] Bug with __int128_t in Clang?

查看:453
本文介绍了与__int128_t在Clang中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个小代码与GCC和Clang一起编译,但是给出不同的结果:

  #include< stdio.h> 

int main(){

__int128_t test = 10;
while(test> 0){
int myTest =(int)test;
printf(?%d\\\
,myTest);
test--;
}

}

到1,预期的行为,而对于Clang它保持计数为负数。使用Clang,如果我用 test- = 1 替换 test - ,那么它也会给出预期的行为。 / p>

__ int128_t是一个GCC扩展,所以上面的结果只适用于非标准C,所以也许__int128_t是在Clang中使用自己承担风险。



这是Clang中的一个错误,还是我没看到错误?



我使用gcc(MacPorts gcc48 4.8-20130411_0)4.8.1 20130411(prerelease)和Apple clang 4.0版(标签/ Apple / clang-421.0.60)(基于LLVM 3.1svn)。

解决方案

这是Clang中的一个错误,它解决了苹果clang 4.0版本之间的一个问题(tags / Apple / clang-421.0.60)基于LLVM 3.1svn)和Apple LLVM版本4.2(clang-425.0.28)(基于LLVM 3.2svn),请参阅注释 - 感谢Carl和H2CO3。


This little code compiles with both GCC and Clang, but gives different results:

#include <stdio.h>

int main(){

  __int128_t test=10;
  while(test>0){
    int myTest=(int)test;
    printf("? %d\n", myTest);
    test--;
  }

}

With GCC this counts from 10 down to 1, the intended behaviour, while for Clang it keeps on counting into negative numbers. With Clang, if I replace test-- with test-=1 then it gives the expected behaviour as well.

__int128_t is a GCC extension, so the above results only apply to non-standard C, so maybe __int128_t is "use at your own risk" in Clang.

Is this a bug in Clang, or did I make some mistake I'm not seeing?

EDIT: I'm using gcc (MacPorts gcc48 4.8-20130411_0) 4.8.1 20130411 (prerelease) and Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn).

解决方案

This was a bug in Clang, which was resolved somewhere between Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn) and Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn), see the comments -- thanks Carl and H2CO3.

这篇关于与__int128_t在Clang中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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