tags:

views:

517

answers:

14

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).

+6  A: 

You can't write device drivers for one.

Otávio Décio
+8  A: 

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.

Richard
The shell extension "limitation" will likely be removed with .NET 4.0 when multiple versions of the CLR can be loaded into the same process.
Dan
@Dan, it is possible starting with 2.0SP1 to load multiple CLR's into the same process. It's just the only CLR's that currently support this are 2.0SP1 and Silvelight so there's not much advantage to doing it now.
JaredPar
+1  A: 

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.

anon
Is your question really effectively whether C# is Turing-complete?
McWafflestix
No, Neil is asking whether the compiler and runtime are self-hosting. I don't know (since I don't work at Microsoft) but based on Rotor (the "shared source" thing they released) I strongly suspect they are *not* self-hosting. Not even in the sense in which Mono is self-hosting.
Mihai Limbășan
No - it's obviously Turing complete, but then so is QBasic! Just because a language is TC doesn't mean you can use it to directly implement some other system. You can obviously do it indirectly - e.g. use QBasic to write an assembler, use the assembler to....
anon
In some MSDN Blog, or (maybe) a Channel 9 video: there is work on a native compiler to be (1) easier to maintain, (2) use for syntax checking/intellisense/... in VS (and give exactly the same results as compiling). But this was, IIRC, targeted beyond .NET 4.
Richard
+1  A: 

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... :-)

McWafflestix
I've heard this opinion time and again but having worked on both MFC and .NET projects, my experience has shown me quite the opposite. I think it's based mostly on theory than practice.
Vulcan Eager
Given File.Delete and RegistryKey.DeleteSubKey are in .NET, it would be quite easy to mess things up. And that's before touching ACLs or P/Invoke. It does not take much to screw things up very completely.
Richard
You can do all of that in C++ PLUS lots more that can not be screwed up in C# .oO(bad pointers)
EricSchaefer
I think the biggest 'screw up' possible in C# is with memory management - look at the issues with undesired object retention in .Net. The biggest reason for it is that everyone's been told it can't happen, so they don't even think about memory leaks.
gbjbaanb
2nd is probably performance problems - possibly because they think the language/compiler/framework will take care of everything for them.
gbjbaanb
A: 

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.

Mihai Limbășan
+3  A: 

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.

CLaRGe
+2  A: 
  • 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.
EricSchaefer
+7  A: 

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.

JaredPar
Your were right on with my intent for the question. It was more application related. Thanks!
Phillip
"Really there are only 2 things you cannot do in C# that you cannot do in C++. " What? =S
John T
@John I tried to clarify this in the first paragrah of the post. This statement is in context to what you can do with regards to building an application / components. Not language features
JaredPar
@JaredPar i think he meant that you said cannot twice
caspin
@Caspin, hah! Completely missed that (fixed). At least I take a bit of humor in mistakes like that.
JaredPar
+12  A: 

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.

Kevin
He did **not** ask "What can be done in Java that can’t be done with VC#?".
EricSchaefer
Of course not, but if I didn't mention it, SOMEBODY in the comments would say to me to recommend Java for cross-platform development.
Kevin
Your latest comment should say, reliable _resource_ management. Try/Finally don't cut it too error prone, 'with' is perfect for locally manage resources, but for shared resource nothing cuts like RAII.
caspin
+3  A: 

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++.

jalf
All you would need is a compiler + a special linker to transform the IL code of your application and the used libraries to native code.
EricSchaefer
The second part is a joke, is it?
EricSchaefer
BTW: Some system calls might be a problem since not all c functions can be called via P/Invoke (e.g. functions that expect callbacks)
EricSchaefer
A joke? Not at all.
jalf
I dont think someone sane would expect to be able to use language features of one language in another.
EricSchaefer
"all you would need is a compiler+special linker", yes well, there is nothing like that so your comment is somewhat facetious. Mono has one, but not .NET. Can you link MS's .NET framework (and all the dependancies together without the source?)
gbjbaanb
jalf wrote "can never". But such absolute statements are almost always false.
EricSchaefer
Are you just being facetious now? First you say it's a joke because it's so obviously true, and now you say it's not necessarily true, and I shouldn't have said "never"? What exactly is your point? Just trolling?
jalf
In any case, I stand by what I said. If you read the C# spec, it includes references to .NET. Hence, .NET has to be present to execute C# code. Of course, *how* .NET is present is open to interpretation. The whole thing could be compiled to native code and embedded in the binary, yes, but that doesn't change anything. The code still has to work on that platform (which means .NET has to exist there in the first place), and it still takes up disk space that may not be justifiable.
jalf
+1  A: 

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).

gbjbaanb
+4  A: 

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.

Artyom
A: 

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.

RED SOFT ADAIR
Using that logic, Operating Systems are a source of problems. You should just avaoid all problems and write your apps at the BIOS level.
Neil N
You might have a different point of view, but by my experience with larger long term projects i clearly see, that its more robust and indeed cheaper if you dont rely on more 3d Party stuff than barley necessary.
RED SOFT ADAIR
A: 

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)

MSalters