Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of doing 100% managed development using C++/CLI?

Tags:

c#

.net

c++-cli

What are the advantages (the list of possible disadvantages is lenghtly) of doing 100% managed development using C++/CLI (that is, compile with /clr:safe which "generates ... assemblies, like those written in ... C#")? Especially when compard to C# (note C++/CLI : Advantages over C# and Is there any advantage to using C++/CLI over either standard C++ or C#? are mostly about managed/unmanaged interop).

For example, here are a few off the top of my head:

  • C++-style references for managed types, not as elegant as full blown non-nullable references but better than nothing or using a work-around.

  • templates which are more powerful than generics

  • preprocessor (this may be a disadvantage!, but macros can be useful for code generation)

  • stack semantics for reference types--automatically calling IDisposable::Dispose()

  • easier implementation of Dispose() via C++ destructor

C# 3.0 added auto-implemented properties, so that is no longer a C++/CLI advantage.

like image 888
Ðаn Avatar asked Feb 02 '10 15:02

Ðаn


People also ask

Should I use C++/CLI?

If you want to interface with lots of unmanaged code, it might be easier to use C++/CLI. You need C++/CLI if you want to write a DLL that is callable from an unmanaged language. For example I have DLLs written in C# that are called by ADA. ADA has to link with an unmanaged library, and that is C++/CLI.

Is C++ CLI for managed?

C++/CLI is variant of the C++ programming language, modified for Common Language Infrastructure. It has been part of Visual Studio 2005 and later, and provides interoperability with other . NET languages such as C#. Microsoft created C++/CLI to supersede Managed Extensions for C++.

Is Managed C++ faster than C#?

Performance: C++ is widely used when higher level languages are not efficient. C++ code is much faster than C# code, which makes it a better solution for applications where performance is important.

Can we use C++ in .NET framework?

The . NET framework can work with several programming languages such as C#, VB.NET, C++ and F#.


1 Answers

I would think that the single biggest advantage is the managed/unmanaged interop. Writing pure managed C++/CLI would (to me at least) without interoping with C# or other .Net languages seems like missing the point entirely. Yeah you could do this, but why would you.

If you're going to write pure managed code why not use C#. Especially (like nobugs said) if VS2010 drops IntelliSense support for C++/CLI. Also in VS2008 the IntelliSense for C++/CLI isn't as good the C# IntelliSense; so from a developer standpoint, it's easier to work/explore/refactor in C# than C++/CLI.

If you want some of the C++ benefits you list like the preprocessor, stack semantics and templates, then why not use C++?

like image 98
cmw Avatar answered Sep 22 '22 06:09

cmw