Hi all,
i was wandering if someone good explain to me about clr? what are some advantages or disadvantages of programming c++ with clr, what are the main differences if there are any?
If I understand it right clr programming is using the .NET framework, but could someone please give me a brief overview of what that means when programming in c++?

Thanks

Recommended Answers

All 5 Replies

C++/CLI is the dialect of C++ which you use under the CLR. Languages that use the CLI have their code converted to MSIL (which is like assembly language, but not quite the same). The MSIL code gets run on a virtual machine, and a just in time (JIT) compiler turns it into bytecode. (I may have glossed over some points, so Wikipedia has great info on all of this for further reading).

When MS created managed C++ (the precursor to C++/CLI) they intended it as a go between in the relationship of native C++ and C#. That is its biggest advantage, IMO. You can write code in C++/CLI, and call it directly from C# (or VB, etc.), whereas calling a native C++ DLL from C# is possible, but requires a more elaborate procedure known as a platform invoke (P/Invoke). Of course the C++/CLI approach isn't perfect, and still requires a lot of translating pointers when there's any native code present. One upside is the ability to write WinForms programs in .NET, rather than operating with Win32API directly.

The downsides are numerous. This is not standard C++ by any stretch of the imagination. Some of the syntax is different, managed pointers are known as handles, which behave largely the same, but require some getting used to (as the memory is now managed by a garbage collector since you're in .NET). It's a bit esoteric (that's kind of what I like about it, actually), so it's not necessarily something that's going to be marketable for the rest of your career (my naive opinion is that shops transitioning into .NET will likely jump into C# directly).

Hopefully that answers most of your questions. I'm not quite sure what you mean by

what that means when programming in c++?

I'm sure that I have missed some details, so if anyone wants to add or subtract anything, please do.

Swt thanks Jonsca :)
That answers alot, and gives me a basis to explore from. Thanks
However with all the libraries available for C++, wont C++ still stay a bit head when developing native programs?
I'm assuming then using .NET wont allow you to use the a program developed in C++\CLI to compile and run on say a Mac then, compared to a general c++ program that can be compiled and run on a mac ?
Sorry if my questions seem a bit naive just trying to cover all my bases :)

However with all the libraries available for C++, wont C++ still stay a bit head when developing native programs?

Yes, it will stay far ahead. C++/CLI was never meant to home in on the C++ market, but was just meant to be a tool that is right for some jobs.

I'm assuming then using .NET wont allow you to use the a program developed in C++\CLI to compile and run on say a Mac then, compared to a general c++ program that can be compiled and run on a mac ?

Not yet, but maybe not ever, I don't know. I know the mono project (http://www.mono-project.com/Main_Page) is trying to get C# and .NET to work across Windows/Mac/*nix, etc., but I don't know if they have any plans to port C++/CLI. A library like Qt (which has GUI elements, but also has other components for things like sockets and database access), is something that would serve you well in developing cross platform apps.

Sorry if my questions seem a bit naive just trying to cover all my bases

No worries, sometimes it's hard to find information out on the net about it. I think some people want to put it out to pasture. I just find it to be an interesting dialect.

Hi
thanks jonsca,
you have been of alot of help
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.