开发者

Ensuring VS 2008 is treating my project as C++ rather than C++/CLI

I'm working in Visual Studio 2008 with native C++.

A colleague wrote a library, and he named one of his classes interface. Here's a constructor:

template <typename DtedInterface>
interface<DtedInterface>::interface (
    std::string const& tleFile,
    std::string const& dtedDir,
    dted::DtedLevel const& dtedLevel,
    double sw_latitude,
    double sw_longitude,
    unsigned int rows,
    unsigned int columns )
    : m_impl ( new interface_impl<DtedInterface> ( theFile, dtedDir, dtedLevel, sw_latitude, sw_longitude, rows, columns ) )
  {}
开发者_如何学编程

What concerns me is that Visual Studio 2008 is highlighting the word interface as a keyword; interface is a keyword within C++/CLI but not C++. This doesn't look like it would be valid C++/CLI, but it's fine for native C++.

Things look like they compile fine, but how do I make sure that Visual Studio is interpreting this as C++ rather than C++/CLI? At some level, it appears that VS views this as C++/CLI. Is it just a keyword highlighting setting?


The Visual Studio IDE and the Visual C++ compiler are two separate entities. Specifically, they are two separate executables (devenv.exe for the IDE and cl.exe for the compiler) that run as separate processes. The IDE simply spawns the cl.exe process to perform the actual compilation.

The IDE has a list of keywords somewhere that simply tells the text editor which words to highlight. It isn't super sophisticated; it doesn't have to be. The compiler has the final say, not the syntax highlighter (or Intellisense for that matter).

As long as the /clr switch is not being passed to the cl.exe process, the compiler will compile the code as native C++ (which is the default setting). The IDE simply feeds in the file paths of your source code and the compiler switches as command-line arguments to the cl.exe process. The syntax highlighting has no bearing on how the compiler interprets the code.


The code will refuse to compile if you're in C++/CLI, so as long as you push "build" and it works, then you know you're in native. There are also pre-defined macros for CLR builds.


If you're really need to verify it's not compiling managed C++, look at the project properties and check the "Common Language Runtime support" setting under the Configuration Properties->General. As well for each file's properties under Configuration Properties->C/C++->General check the "Compile with Common Language Runtime support" setting. If all of those are set to "No Common Language Runtime support", the project is not managed C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜