views:

123

answers:

5

Hi, can someone please tell why , Great Microsoft that created C# language and now we're in C# 4.0 , dont have an important feature that C++\CLI has !!,which is to directly compile and link with un-managed c++ ??

A: 

Because C# is a managed language and intended to be used to write managed code, and C++/CLI already exists to bridge the gap for people who need to directly link unmanaged C/C++ code?

I'm not sure why you would want more native interlink support beyond DllImport/PInvoke. Anything more and you'd just be re-creating C++/CLI with minor syntax differences.

Dan Story
Some people say that's the story behind C# vs. VB.NET, too ;-)
Joey
A: 

You can call C++ code with PInvoke even if, yes, it's not the same.

Andreas Bonini
Yes but e.g : i would then need to implement every matching struct in its managed version as its not necessery with c++ Interop via C++/CLI.
_Avishay_
A: 

Because managed and unmanged code is kept separate. Manged code executes in the CLR, while unmanaged doesn't. You can link you managed code with unmanaged code with P/Invoke.

Eseentially this is to help you marshal information to and from the managed world.

Preet Sangha
Yes but e.g : i would then need to implement every matching struct in its managed version as its not necessery with c++ Interop via C++/CLI.
_Avishay_
So why not just use mc++?
Preet Sangha
+3  A: 

C# is a different language. It doesn't have to include all the features of any other language in order to be useful to its user community. In particular, the emphasis in C# 4.0 has been to move in exactly the opposite direction to C++ by absorbing features from dynamic (scripting) languages instead. Also where C# shares features with C/C++ (e.g. pointers) they are segregated in a special "unsafe" mode to indicate that they are usually undesirable.

Furthermore, as .NET is a multi-language platform, it isn't necessary for every language to include all the features of every other language in order for them to interoperate. They can call each other very easily anyway.

Note that C++ and C# fundamentally disagree with each other on the meanings of many keywords and operators. For example:

class C { }

(Leaving aside whether this should have a semi colon (optionally preceded by a comma-separated list of variable declarations) after it or not, which is going to be tricky to unify.)

Should C be a native C++ class that can be allocated with unmanaged memory and passed to other native code without having to be pinned in the GC? Or should it be a .NET class that can be passed to other .NET libraries?

Or how about:

C c;

Should that declare a reference to C, or create an instance of C?

Or how about:

new C()

Should that allocate on the native C++ heap or on the GC .NET heap?

In C++/CLI all these questions have to be resolved. Learning from the mess that occurred in previous versions, Microsoft clearly separated the two worlds within C++/CLI, by using different keywords, such as gcnew instead of new.

If you attempted to allow C# to compile C++ as it is today, you'd have to rename many operations that are already fundamental to C#, breaking compatibility with all existing C# programs.

What would be the point?

Daniel Earwicker
yes .NET is multi-language platform, but as we can see c# is being in front all of them, so we expect it in c# , heck we even got default params in c# which was VB feature (ofcourse taken from c++)...
_Avishay_
Who's "we"? Speaking for myself, as .NET is a multi-language platform, I expect it to support multiple languages with their own niches. C#'s niche does not include "being a superset of C++."
Daniel Earwicker
when i said "we" i ment c# programmers that are amazed to see new features in the language , but see this un supported feature in the language as disappointment.
_Avishay_
btw: is it true VS2010 doesnt come with Intellisense for C++/CLI ? if thats true , is that a sign goodbye to C++/CLI ?
_Avishay_
A: 

You can call unmanaged C++ from managed code, and you can call managed code from unmanaged C++. See PInvoke and C++/CLI

dthorpe
Yes but e.g for calling native c++ from c#: i would then need to implement every matching struct in its managed version as its not necessery with c++ Interop via C++/CLI.
_Avishay_