如何取消显示“ ISO C ++不支持__int128”警告? [英] How do I suppress the "ISO C++ does not support ‘__int128’ warning?

查看:364
本文介绍了如何取消显示“ ISO C ++不支持__int128”警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用gcc, -Wall -Wextra -Wpedantic 开关和非扩展标准集(例如, -std = c ++ 14 )。但是-我想有一个例外,使用 __ int128 ,这会给我一个警告:

I'm compiling my code with gcc, with the -Wall -Wextra -Wpedantic switches and a non-extension standard set (say it's -std=c++14). But - I want to have an exception and use __int128, and this gets me a warning:

warning: ISO C++ does not support ‘__int128’ for ‘hge’ [-Wpedantic]

我可以禁止显示关于 __ int128 的特定警告吗?另外,我可以在使用这种类型之前和之后暂时取消 -Wpedantic 吗?

Can I suppress the specific warning about __int128? Alternatively, can I temporary suppress -Wpedantic before and after the use of this type?

推荐答案

如果我们为<$ c查阅文档$ 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
}

同时效果很好

这篇关于如何取消显示“ ISO C ++不支持__int128”警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆