源内海合会部分禁用迂腐警告 [英] Partially disable pedantic warnings in gcc within source

查看:123
本文介绍了源内海合会部分禁用迂腐警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让 GCC 闭嘴我的二进制常量的使用。它们使code更具可读性,而且$ P $使用 -pedantic 我遵守,否则pvent我。我要么想拥有像 -fnobinaryconstwarn 开关或类似的(我不认为细读了一阵手册页之后存在),或者使用

I am trying to get gcc to shut up about my usage of binary constants. They make the code more readable, but prevent me from using -pedantic which I comply with otherwise. I would either like to have a switch like -fnobinaryconstwarn or similar (which I don't think exists after perusing the man page for a while) or use a

#pragma GCC diagnostic ignored "-pedantic" 

有选择性地禁用喜欢这里描述的一小段迂腐的警告:
<一href=\"http://stackoverflow.com/questions/965093/selectively-disable-gcc-warnings-for-only-part-of-a-translation-unit\">Selectively禁用GCC警告只是一个翻译单元的一部分?
不幸的是,似乎并没有工作。
我有哪些选择?

to selectively disable the pedantic warnings for a short stretch like described here: Selectively disable GCC warnings for only part of a translation unit? Unfortunately that doesn't seem to work. What are my options?

有关

#pragma GCC diagnostic ignored "-Wpedantic"

的作品,而上面的行不,但它产生一个错误 GCC

推荐答案

也许,你可以使用宏,可以做自己想做的可移植的方式来实现的。
这里有一个简单的例子:

maybe, you could use a macro which can do what you want to achieve in a portable manner. here's a short example:

#include <stdio.h>

#define BINARY(N) strtol(#N, 0, 2)

int main()
{
    unsigned int piece = BINARY(10010101);
    printf("%u\n", piece);

    return 0;
}

在理论上,GCC应该能够优化调用strtol将离开,你不会失去可读性。

in theory, gcc should be able to optimize the calls to strtol away and you don't lose readability.

编辑:看来,GCC不优化strtol将呼吁远离截至目前。然而,你的表现应该的损失可以忽略不计。

It seems that gcc does NOT optimize the strtol calls away as of now. However, your performance loss should be negligible.

干杯!

这篇关于源内海合会部分禁用迂腐警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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