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

纵然是瞬间 提交于 2019-12-19 19:45:46

问题


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 disable this?

I already changed settings to compile the code only as a C code, but no effect on this.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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




回答5:


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!!




回答6:


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



来源:https://stackoverflow.com/questions/299565/how-to-disable-interface-keyword-on-visual-c-express-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!