Alternative tokens (not, and, etc…) in VisualStudio 2013

后端 未结 3 1423
栀梦
栀梦 2020-12-07 02:46

The \"not\", \"and\", etc... are keywords in C++ (macros in C). Is there any way to \"enable\" them in Visual Studio 2013? I\'m able to use the words as macroses with

相关标签:
3条回答
  • 2020-12-07 02:50

    On a more recent version of VS (tested on Version 15.7.0 Preview 3.0); ensure that conformance mode is set for visual studio:

    It then compiles with the alternative operator representations.

    0 讨论(0)
  • 2020-12-07 02:57

    Using /Za seems to enable them without including iso646.h, see it live, the following program produces an error without using /Za but works fine otherwise:

    int main()
    {
        int x = 1, y = 0 ;
        if (x and y)    
        {
        //...  
        }
    
        return 0;
    }
    

    As ta.speot.is indicates /Za disables extensions, the following documentation indicates you must include ios646.h otherwise:

    Under /Ze, you have to include iso646.h if you want to use text forms of the following operators:

    and it lists the alternative tokens below.

    Note, I knew I saw this before, I include a link to a bug report for this in my answer to a similar question. Although this does not include the workaround noted above.

    Note 2: Cheers and hth. - Alf indicates that there may be many undesirable consequences to turning off extension and therefore you may be better off just including iso646.h.

    0 讨论(0)
  • 2020-12-07 03:13

    Use a forced include (option /FI) of the iso646.h header.

    For work in the command interpreter you can put this in your CL environment variable, or e.g. in a response file.


    Turning off Visual C++ language extensions with /Za can also do the trick, at the cost of rendering the compiler pretty much useless – since Microsoft code such as the Windows API headers generally uses the extensions.

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