Phillip
Phillip

Reputation: 440

What can be done in VC++ (native) that can't be done with VC#?

What can be done in VC++ (native) that can't be done with VC#?

From what I can tell the only thing worth using VC++ native for is when you need to manage memory yourself instead of the CLR garbage collector, which I haven't seen a purpose in doing either (but thats for another question to be asked later).

Upvotes: 8

Views: 739

Answers (14)

MSalters
MSalters

Reputation: 180303

Using SSE instructions seems to be one of these cases. Some .NET runtimes will use some SSE instructions, depending on your code. But in VC++, you can use the SSE intrinsics directly. So, if you're writing a multimedia code, you'd probably want C++. (C++/CLI might work as well, presumably)

Upvotes: 0

RED SOFT ADAIR
RED SOFT ADAIR

Reputation: 12238

The Main difference is:

  • C++ is a core language with which you can build stand-alone programs. These Programs communicate directly with the the operating system and nothing else. C++ compilers exist for more or less all platforms (operating systems).

  • C# is a language that conforms to the CLS. A program written in C# can not start without a CLI engine (.NET Framework, Mono, etc.). A Program written in C# communicates with the .NET framework AND with the operating system. You have a man in the middle. Like all servicing personal, this man can help but it will cause additional trouble. If you want to port, you have a different man in the middle etc. CLI Implementations do not exist for all platforms.

By my opinion every additional framework is a additional source of problems.

Upvotes: 0

JaredPar
JaredPar

Reputation: 755587

I'm not sure if you're talking about language features or applications. My answer though is for applications / components.

Really there are only 2 things you cannot do in C# that you can do in C++.

  • You cannot use C#, or any other .Net language, to write a component for a system that only accepts native components
  • You cannot use C#, or any other .Net language, to alter certain properties of a CCW for which the CLR does not allow customization

The most notable item here is Device Drivers. This is a framework that only accepts native components and there is no way to plug in a managed component.

For everything else it's possible to do the same thing in C# as it is in C++. There are just a lot of cases where you simply don't want to and a native solution is better. It's possible for instance to manage and manipulate memory in C# via unsafe code or IntPtr. It's just not nearly as easy and generally there's no reason.

Upvotes: 7

Artyom
Artyom

Reputation: 31281

I think there are several important points:

You can do anything in C#/C++/Java/Python/Lisp or almost any other language, finally all of them Turing complete ;)... The question is it suits your needs?

  1. There is one big and extreamly important limitation of C#... It runs only one single platform Windows... (Mono is still not mature enough).
  2. There are many applications where GC is just a waste of resources, applications that can't afford you throw up 1/2 of memory untill next gc cycle: Games, Data Bases, Video auido Processing and many other mission critical applications.
  3. Real Time applications (again games, video processing and so on). Non-deterministic GC makes life much harder for them.

In fact, most of desktop applications: Web Browsers, Word Processors, Desktop Environment itself (like Windows Explorer, KDE or Gnome) are written in compiled languages with careful thinking about resources... Otherwise, they would just be terrible bloated applications.

Upvotes: 4

gbjbaanb
gbjbaanb

Reputation: 52699

There's also hard real-time applications. Any language with a GC cannot be used, just in case it decides to collect during a time-constrained part of the code. Java was notorious for not even allowing you to try (hence the EULA about not using it for software "intended for use in the design, construction, operation or maintenance of any nuclear facility"

(yes, I know they've since made a modified version of Java for real time systems).

Upvotes: 1

Richard
Richard

Reputation: 109210

With P/Invoke there is very little that is impossible in .NET (most obviously device drivers).

There are also things where the advice is to not use .NET (e.g. shell extensions, which get loaded into any process that opens a file dialogue1).

Finally there are things which will be much harder in .NET, if possible at all (e.g. creating a COM component that aggregates the FTM).

1 This can create a problem if that process is already using a different version of .NET. This should be alleviated in the future with .NET 4 having the ability to support side by side instances of the runtime.

Upvotes: 8

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 248289

There are two obvious answers:

  • VC# can never run without the .NET framework. Native C++ can. That may be necessary in some areas (others have mentioned device drivers, but more common examples might simply be clients where the .NET framework is not installed. Perhaps you're distributing an application and you know not all of your customers are willing to install .NET, so your sales would go up if you made an app that just worked without the dependency on .NET. Or perhaps you're working on some mobile device where the couple of megabytes taken up by the .NET CF can not be justified. Or shell extensions where using .NET can cause nasty problem for the user.
  • And VC# can never use C++ language features. Native C++ can. (Managed C++ can too, of course, but that's a different issue). There are, believe it or not, things that can be done more conveniently or elegantly in C++. And they're only accessible if you're programming in C++.

System calls are no problem, however. p/invoke lets you do those from C#, almost as easily as you could from C++.

Upvotes: 3

Kevin Anderson
Kevin Anderson

Reputation: 7010

Cross-platform development. Yes Mono exists, and Java's somewhat more predictable to have it function EXACTLY the same on more platforms, you can find a C/C++ compiler for just about any platform out there, where you can't with C#.

Also linking into 3rd-party libraries, while I'm sure there's a way to leverage them in C#, you'll be able to take advantage of them without interop (Marshaling, etc) in C++.

Edit: one last thing: RELIABLE memory management. Yes you can use dispose(), and try-finally, but there's nothing quite like KNOWING the memory is gone when it's popped off of the stack. Through techniques like RAII, when you use well-constructed classes, you will KNOW when your classes release resources, and not waiting around for the GC to happen.

Upvotes: 13

EricSchaefer
EricSchaefer

Reputation: 26410

  • inline assembler
  • You cannot use C++-Libraries with classes (P/Invoke can only be used for functions AFAIK)
  • You cannot use callbacks with P/Invoke.

Upvotes: 2

CLaRGe
CLaRGe

Reputation: 1831

Whereas writing shell extensions in Windows XP was possible in C# it is next to impossible to write shell extensions for Vista and Windows 7. Shell extensions and Namespace extensions (and anything else that uses the new Properties system) (kindof) must be done in C++ unless you're into pain.

Upvotes: 3

Mihai Limbășan
Mihai Limbășan

Reputation: 67836

For example, it makes sense to use C++ if it's harder to translate the header files for existing libraries than it is to give up the existing managed libraries.

Upvotes: 0

Paul Sonier
Paul Sonier

Reputation: 39520

This is tongue in cheek, but it also is an answer to your question... you can screw things up much more severely in VC++ than you can in VC#. Not that you can't manage to screw things up severely in VC#, but in general, you can screw them up easier and more thoroughly in VC++.

Again, kind of tongue in cheek, but also an answer to your question. Perhaps not what you were hoping for, but... :-)

Upvotes: 1

anon
anon

Reputation:

Is C# in particular and .NET in general self compiling yet (this is not a troll, I genuinely don't know)? If not, you can use VC++ to write C# and .NET, but you can't use C# to do the same job.

Upvotes: 1

Otávio Décio
Otávio Décio

Reputation: 74320

You can't write device drivers for one.

Upvotes: 6

Related Questions