当前位置:网站首页>Why is this an undefined behavior- Why is this an undefined behavior?

Why is this an undefined behavior- Why is this an undefined behavior?

2022-07-05 02:36:00 Bustling city

problem :

My answer to this question was this function: I am right. The answer to this question It's this function :

inline bool divisible15(unsigned int x) {    //286331153 = (2^32 - 1) / 15    //4008636143 = (2^32) - 286331153    return x * 4008636143 <= 286331153;}

It perfectly worked on my machine with VS2008 compiler, however here it doesn't work at all. It is completely applicable to my machine and VS2008 compiler , but ad locum It doesn't work at all .

Does anyone has an idea, why it I get different results on different compilers? Does anyone have an idea , Why do I get different results on different compilers ?unsigned overflow isn't undefined behavior.unsigned Overflow is not an undefined behavior .

Important note: after some test it was confirmed it is faster than taking the remainder of the division by 15. (However not on all compilers) Important note : After some testing , Make sure it's better than dividing the remainder of the division by 15 faster .( But not on all compilers )


Solution :

Reference resources : https://stackoom.com/en/question/1GUVX
原网站

版权声明
本文为[Bustling city ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140914023668.html