What does the fpermissive flag do?

前端 未结 4 2157
孤城傲影
孤城傲影 2020-11-28 23:48

I\'m just wondering what the -fpermissive flag does in the g++ compiler? I am getting:

error: taking address of temporary [-fpermissive]<

相关标签:
4条回答
  • 2020-11-28 23:50

    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.

    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".

    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. =]

    0 讨论(0)
  • 2020-11-29 00:03

    The -fpermissive flag causes 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
    Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile.

    0 讨论(0)
  • 2020-11-29 00:03

    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 some kind 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.

    0 讨论(0)
  • 2020-11-29 00:09

    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.

    Bottom line: don't use it unless you know what you are doing!

    0 讨论(0)
提交回复
热议问题