g++ 的有趣逻辑

灌水区

ppip @ 2022-07-10 20:05:11

#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

咋搞的捏


by Nevergonna_CCF @ 2022-07-10 20:08:51

@ppip auto毁生涯


by Nevergonna_CCF @ 2022-07-10 20:09:26

还有为什么你的帖子这么特别


by ppip @ 2022-07-10 20:10:27

@lmw_AK_noip 哪里特别了


by Aleph_zero @ 2022-07-10 20:11:33

@lmw_AK_noip 您是exlg?


by Nevergonna_CCF @ 2022-07-10 20:12:00


by Nevergonna_CCF @ 2022-07-10 20:12:17

@for_i_in_range 啊对对对


by ppip @ 2022-07-10 20:12:55

@lmw_AK_noip 额,我发错板块了,阴该是学术的


by LiaoYF @ 2022-07-10 20:13:02

@ppip 你名字不对劲,里面放了Unicode反转


by hjxhjx @ 2022-07-10 20:15:05

@Mr_LiaoYifan 是badge


by ppip @ 2022-07-10 20:15:38

能不能别灌水了,大家正经回答问题


| 下一页