Is it possible to turn off support for “and” / “or” boolean operator usage in gcc?

后端 未结 4 2027
忘了有多久
忘了有多久 2020-12-11 06:15

GCC seems to allow \"and\" / \"or\" to be used instead of \"&&\" / \"||\" in C++ code; however, as I expected, many compilers (notably MSVC 7) do not support this. T

相关标签:
4条回答
  • 2020-12-11 07:05

    They are part of the C++ standard, see for instance this StackOverflow answer (which quotes the relevant parts of the standard).

    Another answer in the same question mentions how to do the opposite: make them work in MSVC.

    To disable them in GCC, use -fno-operator-names. Note that, by doing so, you are in fact switching to a non-standard dialect of C++, and there is a risk that you end up writing code which might not compile correctly on standard-compliant compilers (for instance, if you declare a variable with a name that would normally be reserved).

    0 讨论(0)
  • 2020-12-11 07:05

    Have you considered any code analysis tools? Something similar to FxCop? With FxCop you can write your own rules( check for && ) and you can set it to run during the pre-compile stage.

    0 讨论(0)
  • 2020-12-11 07:08

    -pedantic-errors may help for this, among other gnu-isms.

    0 讨论(0)
  • 2020-12-11 07:10

    The words are standard in C++ without the inclusion of any header.

    The words are standard in C if you include the header <iso646.h>.

    MSVC is doing you no service by not supporting the standards.

    You could, however, use tools to enforce the non-use of the keywords. And it can be a coding guideline, and you can quickly train your team not to make silly portability mistakes. It isn't that hard to avoid the problem.

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