且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何取消显示“ ISO C ++不支持__int128”警告?

更新时间:2022-06-25 00:36:10

如果我们为文档$ c> -Wpedantic 我们可以注意到以下内容:

If we consult the documentation for -Wpedantic we can note the following:


__ extension __ 之后的表达式。

实验位表明,即使在以下标志下,它也可以按预期定义变量: b
$ b

A quick bit of experimentation shows that this allows one to define variables as expected, even under the flag:

__extension__ __int128 hge{};

但是,如果我们打算经常使用这种类型的话,那当然很麻烦。使用类型别名可以减轻这种麻烦。尽管我们在这里需要小心,但是 __ extension __ 属性必须在 entire 声明之前:

But of course that's rather cumbersome if we intended to use this type often. The way to make this less intractable is with a type alias. Though we need to be careful here, the __extension__ attribute must precede the entire declaration:

__extension__ typedef __int128 int128;

您可以看到它正在运行此处

You can see it working here.

另一种方法遵循您最初的思路,就是在类型别名周围使用诊断性编译指示:

An alternative approach, and one that follows your original line of thought, is to use diagnostic pragmas around the type alias:

namespace my_gcc_ints {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
    using int128 = __int128;
#pragma GCC diagnostic pop
}

同时效果很好