C++ fpermissive 标志有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8843818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the fpermissive flag do?
提问by mmirzadeh
I'm just wondering what the -fpermissive
flag does in the g++ compiler? I am getting:
我只是想知道-fpermissive
g++ 编译器中的标志是什么?我正进入(状态:
error: taking address of temporary [-fpermissive]
错误:取临时地址 [-fpermissive]
which I can solve by giving the -fpermissive
flag to the compiler.
我可以通过将-fpermissive
标志提供给编译器来解决 。
EDIT: I just found what was causing the temporary address error part! I'm going to fix that part right now.
编辑:我刚刚发现导致临时地址错误部分的原因!我现在要修复那个部分。
回答by cli_hlt
Right from the docs:
来自文档:
-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using-fpermissive
will allow some nonconforming code to compile.
-fpermissive
将一些关于不符合代码的诊断从错误降级为警告。因此, using-fpermissive
将允许编译一些不合格的代码。
Bottom line: don't useit unless you know what you are doing!
底线:除非您知道自己在做什么,否则不要使用它!
回答by David Schwartz
The -fpermissive
flagcauses the compiler to report some things that are actually errors (but are permitted by some compilers) as warnings, to permit code to compile even if it doesn't conform to the language rules. You really should fix the underlying problem. Post the smallest, compilable code sample that demonstrates the problem.
该-fpermissive
标志使编译器将一些实际上是错误的东西(但某些编译器允许)报告为警告,以允许代码编译,即使它不符合语言规则。你真的应该解决根本问题。发布演示问题的最小的、可编译的代码示例。
-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using-fpermissive
will allow some nonconforming code to compile.
-fpermissive
将一些关于不符合代码的诊断从错误降级为警告。因此, using-fpermissive
将允许编译一些不合格的代码。
回答by leftaroundabout
When you've written something that isn't allowed by the language standard (and therefore can't really be well-defined behaviour, which is reason enough to not do it) but happens to map to somekind of executable if fed na?vely to the compiling engine, then -fpermissive
will do just that instead of stopping with this error message. In some cases, the program will then behave exactly as you originally intended, but you definitely shouldn't rely on it unless you have some very special reason not to use some other solution.
当你写了一些语言标准不允许的东西(因此不能真正定义明确的行为,这是不这样做的充分理由)但碰巧映射到某种可执行文件,如果喂食 na? vely 编译引擎,然后-fpermissive
将执行此操作而不是停止此错误消息。在某些情况下,该程序将完全按照您最初的预期运行,但您绝对不应该依赖它,除非您有一些非常特殊的理由不使用其他解决方案。
回答by breakpoint
If you want a real-world use case for this, try compiling a very old version of X Windows-- say, either XFree86 or XOrg from aboout 2004, right around the split-- using a "modern" (cough) version of gcc, such as 4.9.3.
如果您想要一个真实世界的用例,请尝试使用“现代”(咳嗽)版本的 gcc 编译一个非常旧版本的 X Windows - 例如,大约 2004 年左右的 XFree86 或 XOrg,就在拆分前后,例如 4.9.3。
You'll notice the build CFLAGS specify both "-ansi" and "-pedantic". In theory, this means, "blow up if anything even slightly violates the language spec". In practice, the 3.x series of gcc didn't catch very much of that kind of stuff, and building it with 4.9.3 will leave a smoking hole in the ground unless you set CFLAGS and BOOTSTRAPCFLAGS to "-fpermissive".
您会注意到构建 CFLAGS 指定了“-ansi”和“-pedantic”。从理论上讲,这意味着“如果有任何稍微违反语言规范的东西就会爆炸”。在实践中,3.x 系列的 gcc 并没有抓住很多这种东西,除非你将 CFLAGS 和 BOOTSTRAPCFLAGS 设置为“-fpermissive”,否则用 4.9.3 构建它会在地上留下一个冒烟的洞。
Using that flag, most of those C files will actually build, leaving you free to move on to the version-dependent wreckage the lexer will generate. =]
使用该标志,大多数 C 文件将实际构建,让您可以自由地移动到词法分析器将生成的依赖于版本的残骸。=]