Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 iso646.h included. But VS seems not be able to recognize them as keywords.

like image 854
Denis Gladkiy Avatar asked Sep 24 '14 03:09

Denis Gladkiy


3 Answers

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.

like image 96
Shafik Yaghmour Avatar answered Nov 11 '22 13:11

Shafik Yaghmour


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.

like image 42
Cheers and hth. - Alf Avatar answered Nov 11 '22 14:11

Cheers and hth. - Alf


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: enter image description here

It then compiles with the alternative operator representations.

like image 1
wally Avatar answered Nov 11 '22 14:11

wally