gpt4 book ai didi

c++ - 以不同的行为 boost uint128_t

转载 作者:行者123 更新时间:2023-11-28 05:41:56 36 4
gpt4 key购买 nike

我有以下程序:

#include <arpa/inet.h>
#include <netinet/in.h>
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

int main() {
boost::multiprecision::uint128_t res;
inet_pton(AF_INET6, "2001:db8:8714:3a90::12", &res);
cout<<res<<endl;
}

根据我使用的编译器,我得到了 3 种不同的行为:

clang++-3.8

23926103924128485722661168748298043680

g++-5.3.0

23926103924128485722661168748298043680

clang++-3.6

3087860000

g++-6.1.0

In file included from /usr/local/include/boost/config.hpp:61:0,
from /usr/local/include/boost/cstdint.hpp:36,
from /usr/local/include/boost/multiprecision/cpp_int.hpp:11,
from main.cpp:4:
/usr/local/include/boost/multiprecision/cpp_int.hpp:181:4: error: right operand of shift expression '(1u << 63u)' is >= than the precision of the left operand [-fpermissive]
BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1));
^
/usr/local/include/boost/multiprecision/cpp_int.hpp:404:4: error: right operand of shift expression '(1u << 63u)' is >= than the precision of the left operand [-fpermissive]
BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1));
^
/usr/local/include/boost/multiprecision/cpp_int.hpp:556:4: error: right operand of shift expression '(1u << 63u)' is >= than the precision of the left operand [-fpermissive]
BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1));
^

c++14 在所有情况下均已启用。有人可以解释为什么会这样吗?预期的行为当然是第一个。

最佳答案

inet_pton 取一个 void*

您正在传递具有未记录布局的非原始地址。

结果充其量是实现定义的。可能是未定义的行为。

关于c++ - 以不同的行为 boost uint128_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925881/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com