1

All of my commercial experience is based on high level languages like .NET (VB and C#). I have academic experience with C and C++ (university).

I don't full understand how Visual C++ fits into the .NET way. I have experience using Cygwin to compile c++ programs for Linux (at university).

Am I correct in stating that Visual C++ will compile into Intermediary language like C# and VB.NET? I assume that Visual C++ is used by developers that want to target Windows only and Cygwin is used by C++ developers who want to target multiple environments?

The reason I ask is because I am using a C++ component (written by another developer) as part of a .NET app.

I have read many Visual C++ articles online today but I have not yet found the answer I am looking for.

w0051977
  • 15,099
  • 32
  • 152
  • 329

2 Answers2

3

No. C++ is compiled directly to machine code, there is no intermediate step like .NET's IL with a just-in-time compiler to translate it to machine code at runtime.

If you have a need to interop between C++ and .NET code then you'll probably want to take a look at C++/CLI. A language that merely resembles C++ but is very good at bridging the gap between native C++ and the .NET runtime.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks +1 for the reference to: C++/CLI. I assume that if the code was written in classic C++ then it will have to be rewritten in this C++/CLI? – w0051977 Oct 07 '12 at 18:57
  • The point of C++/CLI is that you don't have to rewrite that kind of code. The C++/CLI compiler can also compile native C++ code. *And* you can write a managed wrapper class to expose a native C++ class to managed code. – Hans Passant Oct 07 '12 at 19:04
  • Thanks. If you can compile native C++ using the C++/CLI compiler, then how would you write a wrapper class? I assume that it would be similar to using a COM component (VB6) in .NET i.e. by exposing a type library. – w0051977 Oct 07 '12 at 19:29
  • You learn a new language by visiting your local library and checking out a book. A sample wrapper is here: http://stackoverflow.com/a/2691448/17034 – Hans Passant Oct 07 '12 at 19:42
  • Thanks. I have read plenty of C++ books and .NET books, but nothing on C++/CLI. – w0051977 Oct 07 '12 at 20:06
2

Am I correct in stating that Visual C++ will compile into Intermediary language like C# and VB.NET?

Yes and no. If you use C++/CLI (which is a Microsoft proprietary language included in Visual C++, similar to the C++ language but definitely not the same thing), then yes, it will compile to .NET intermediate code. If you turn off C++/CLI and use standard C++, then it will compile to native code and not use the .NET runtime.

Cygwin is used by C++ developers who want to target multiple environments?

Cygwin is not required if you want to target multiple environments. However, code written in a portable way that compiles with Cygwin is more likely to compile on GCC on other platforms too. You can write portable code with any compiler.

Cygwin to compile c++ programs for Linux

I think you might be a wee bit confused on this point. Cygwin is a package that provides a GCC compiler (and POSIX-like) environment for Windows. Cygwin does not run on Linux, there's no need.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285