g++ 的有趣逻辑
  • 板块灌水区
  • 楼主ppip嘟嘟嘟
  • 当前回复12
  • 已保存回复12
  • 发布时间2022/7/10 20:05
  • 上次更新2023/10/27 21:11:31
查看原帖
g++ 的有趣逻辑
374433
ppip嘟嘟嘟楼主2022/7/10 20:05
#include <bits/stdc++.h>
using namespace std;
template <typename T>
const char *f(T x)
{
    // type name
    return typeid(x).name();
}
int main()
{
    auto t1 = -2147483647 - 1;
    auto t2 = -2147483648;
    auto t3 = -9223372036854775807;
    auto t4 = -9223372036854775808;
    int a;
    long b;
    long long c;
    unsigned long long d;
    __int128 e;
    // cout << t1 << " " << t2 << " " << t3 << " " << t4 << endl;
    // if t4 is __int128 it will CE
    cout << f(t1) << " " << f(t2) << " " << f(t3) << " " << f(t4) << endl;
    cout << f(a) << " " << f(b) << " " << f(c) << " " << f(d) << " " << f(e) << endl;
    return 0;
}

该程序在本机的输出:

i l l n
i l x y n

但是报了一个 warning:

/home/ppip/codes/cz.cpp:14:16: warning: integer constant is so large that it is unsigned
   14 |     auto t4 = -9223372036854775808;
      |                ^~~~~~~~~~~~~~~~~~~

(还有一堆 uninitialized 就不写了)

但是由输出,t4 被视为 __int128

咋搞的捏

2022/7/10 20:05
加载中...