如何在c++14中从int获取原始long long值?

问题描述 投票:0回答:0

我们有一个遗留代码,其中包含一些 int 变量,并且该变量的数据类型无法更改,因为该代码位于共享库中,并且其他依赖客户端必须重新编译。

问题是我们需要从 int 数据类型变量检索原始 64 位变量,下面是我想出的可能的转换,但这看起来很丑陋,我不确定它是否适用于所有用例。那么有没有更好的方法从给定的 32 位数字中检索原始 64 位数字。

int main() {
    int x = 6448575603;
    long long x_convert = (2147483648LL + 2147483648LL +2147483648LL+2147483648LL + (long long)x);
    long long y = 6448575603;
    std::cout<<"x is "<<x_convert<<std::endl;
    std::cout<<"y is "<<y<<std::endl;
    return 0;
}
c++ c++14
© www.soinside.com 2019 - 2024. All rights reserved.