What is the meaning of C ++ / CLI?

I am wondering what is the use of C ++ / CLI. It seems to me that basically C ++ works on .Net, am I mistaken in this thinking? What is this for? Why not just use C # or some other really manageable language?

+4
source share
4 answers

Here are a few benefits of C ++ / CLI in just C ++ or say C #

  • This is a great language for writing a large component that captures native and managed code.
  • Provides a fast (er) conversion path from a purely native C ++ code base to a purely managed one. Without C ++ / CLI, the best option would be to rewrite
+11
source

There are several interesting things in C ++ / CLI that C # doesn't have:

  • Strongly typed box. If you set int to object in C #, you will lose any information about what the original type is. Not in C ++ / CLI.

  • The difference between destructors and finalizers. In C #, you need to manually implement IDisposable and don't forget to call Dispose . In C ++ / CLI, you simply drop the cleanup code in the destructor (which is automatically compiled into the Dispose method) and put the cleanup code for control only in the finalizer.

  • The difference between stack and heap semantics for variables. Stack is standard, and the reference types associated with the stack will be automatically destroyed (deleted) - you do not need to remember delete them, just release them from the scope. In short, it's much easier to handle unmanaged resources in C ++ / CLI than any other .NET language.

  • Function pointers. Now this is less of a difference with anonymous delegates and lambda syntax in C #, but back in 2005 it was something more.

  • Access to all access modifiers implemented in the common language runtime. You can explicitly specify public, protected or private both for one assembly and for external assemblies. All you have in C # (except for the obvious public , protected , private ) is the internal and protected internal modifiers, the first of which means "publicly internally, private from the outside," and the latter means "publicly accessible, protected from the outside." In C ++, you can make the class "protected AND internal", which means that the member is only available for derived classes in the same assembly.

  • Value classes Strange, but probably helpful to someone!

Here is a more detailed explanation of all this and more here . In short, other managed languages ​​are C #, VB.NET, F #, etc. - In fact, they do not give you full access to everything that the CLR can do, more than 90%. C ++ / CLI allows you to do almost everything you need in the CLR specification.

+10
source

A few reasons for C ++ / CLI:

  • it allows you to integrate / mix managed and unmanaged code at a much more subtle level than other .NET languages.
  • Managed C ++ was not particularly successful; C ++ / CLI was an attempt to make the .NET paradigm fit better with existing C ++ idioms.
  • While I do not think that someone thought that he would overtake C # in popularity, I think that there were people who thought that he would have a higher level of success than him. And again, for everyone, I know that it is very successful. I did nothing but toy stuff, but when Visual C ++ Team Blog pointed out that VS2010 did not have IntelliSense for C ++ / CLI , there was a bit of a fiery assault back. Much more than I expected (I'm not sure I expected MS).

Microsoft really did some things in C ++ / CLI that I think are interesting, even if you have no interest in .NET: how they handle adding new keywords in a way that affects existing C ++

  • keywords with multiple words (or "spaced") (I think this method is patented or patented by Microsoft)
  • contextual keywords
  • 'namespaced' keywords

See the Sutter article for more details.

+4
source

Gosh, I used C ++ / CLI downloads when you need to do something high-performance (like image processing using SIMD), interact with native C ++ (like OpenGL code, existing legacy C ++ code) or just look smart.

ok;) Maybe not the last

Decreased support for him would be a big loss of IMO ..

+2
source

Source: https://habr.com/ru/post/1303621/


All Articles