How to disable interface keyword on visual C++ Express 2008?

后端 未结 6 703
遥遥无期
遥遥无期 2021-01-18 11:11

I am compiling a legacy C code here and there is a lot of variables and struct members named \"interface\", but VC2008 express is complaining about these, do you know how to

相关标签:
6条回答
  • 2021-01-18 11:54

    You can define WIN32_LEAN_AND_MEAN to avoid inclusion of this definition. See MSDN Docs

    0 讨论(0)
  • 2021-01-18 11:58

    Do a

    #define interface QQInterface
    

    before your code (eg. in the header file), this way everywhere where the keyword interface is used, the compilers sees "QQInterface", which is not a keyword. If all code includes this define, you will not get compiler or linker errors.

    0 讨论(0)
  • 2021-01-18 12:05

    I faced a similar problem while compiling C++ code which included a dbus header file. since dbus has several functions where it uses "interface" as an I/P parameter name, which happens to be C++ keyword, I got following error: error: expected ',' or '...' before 'struct'.

    When I tried this:

    #ifdef interface 
    #undef interface 
    #endif 
    

    it solved the issue. Not sure if using dbus C++ binding would have been better. Anyways I was not using dbus, just had a remote dependeny on one of dbus headers, this solution just worked fine!!

    0 讨论(0)
  • 2021-01-18 12:08

    If you are trying to compile reasonably portable C code, it might be worth disabling the Microsoft language extensions (/Za on the command line, Configuration Properties > C/C++ > Language in VS) and see if the code compiles then.

    0 讨论(0)
  • 2021-01-18 12:13

    Problem is that MS #defines interface to struct so that

    interface Name {...}
    

    can be used in COM c++ code. (objbase.h:199: #define interface __STRUCT__)

    Just #undef interface after including Windows.h ..

    0 讨论(0)
  • 2021-01-18 12:17

    "interface" a should not be a keyword in C nor ISO C++. It is a keyword in the Managed Extensions for C++, so, I guess, somewhere in your configuration you are still telling it to create code for .NET. Make sure everywhere is set to "Native Code"

    However, it's quite possible that you CANNOT set it to Native Code in the Express edition --- That's just a guess, but it reasonable considering MS positioning of the Express/Standard/Pro editions.

    UPDATE: Disregard that last paragraph. MSFT insists that you can create native Win32 apps with VisualC++ Express: http://www.microsoft.com/express/vc/

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