views:

571

answers:

9

It's my understanding that C#, though created by Microsoft, is a programming language that can be used or implemented for things other than .NET programming. For example, I could create a compiler for C# to target native x86 or other processors or even a JVM. Is my understanding incorrect? Does anyone know if C# is used for anything besides .NET?

A: 

You can compile a C# program on Mono. But that probably doesn't count.

Mono is an alternative implementation of the Common Language Infrastructure (CLI) that runs on Linux and various other operating systems. As mentioned in other places, both C# and the CLI are ECMA standards and can be implemented by anyone who cares to do so.

Rotor is another non .NET implementation.

jrcs3
I beg to differ...Mono is not .NET. It is a platform written in C#. ;)
dboarman
+6  A: 

C# is used for an experimental operating system called 'Singularity' which is written in the managed level from the ground up. An interesting project to watch!

Edit: Thanks Jörg W Mittag for his comment - Helios is actually a modified form of Singularity to support satellite kernels, to quote from the paper I am reading right now 'Helios is an operating system designed to simplify the task of writing, deploying and tuning applications for heterogenous platforms. Helios introduces satellite kernels, which export a single uniform set of OS abstractions across CPUs of disparate architectures and performance characteristics. Satellite Kernels allows developer to write applications against familiar operating system APIs and abstractions.'...interesting...

Hope this helps, Best regards, Tom.

tommieb75
Well, there's not that much to watch. The project ended years ago, and most of the researchers are now working on Helios (which is based on Singularity and expands its ideas towards heterogeneous systems).
Jörg W Mittag
+2  A: 

You are correct that it can be used for other things. It's a language specification...you can compile it into anything you like if you take the time, but it'd be a tremendous effort.

I don't know of any other uses besides Mono as jrcs3 said, but hopefully Eric Lippert will chime in and give you a compiler point of view on C#

Nick Craver
+1  A: 

As far as I'm aware, all currently existing implementations of C# build to CIL and run in the .NET CLR or compatible environment, and the only alternative to the .NET CLR I am aware of is Mono.

In other words, all current versions of C# build to run in .NET or Mono.

.NET and Mono use the same 'binaries', so effectively all current C# compilers have only one target.

Drakonite
A: 

There are indeed tools to convert a .NET assembly to a standalone executable or library, so that you don't need your clients to have the .NET framework. This also further protects your code against reverse-engineering to some degree -- you can't use Reflector to see the .NET source on a native binary.

See Remotesoft Salamander .NET Protector, for instance.

But, that isn't strictly C# -> native; Salamander converts the MSIL to native code.

On the other hand, there is at least one academic project on making a C# -> native compiler using LLVM, called LLVM#.

Mark Rushakoff
$1249 for a single developer...that's a bit steep if you're a lone programmer working on project to market...
tommieb75
+2  A: 

C# itself is a specification specified by the ECMA that "specifies the form and establishes the interpretation of programs written in the C# programming language." as is the CLR. The most popular implementation of these is currently provided by Microsoft, which is the C#.net that you know. C# and the CLR are open standards, meaning that anyone can implement them themselves, hence the formation of mono, a C# compiler for mac/linux. Compare this to java, who's only implementation is provided by sun. It's not an open standard, so you can't create your own implementations.

from wikipedia:

Mono "An open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET"

DotGNU "is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework"

Dot Net Anywhere is a .net CIL interpreter for targeting embedded systems.

CrazyJugglerDrummer
Nitpick: the CLR is Microsoft's proprietary implementation. The specification is called *VES* (virtual execution system).
Jörg W Mittag
Also, it's not true that there is only one implementation of Java. Sun alone has *four* implementations, Oracle has one, IBM has at least two, Microsoft has/had one, Apache has one, RedHat has one, Apple has one, Azul has one, pretty much every cell phone vendor has one, Google has one and then there's dozens of Open Source and Research ones.
Jörg W Mittag
By Google's implementation, do you mean the one on Android? Isn't that normal Java compiled for a non-standard JVM?
Benny Jobigan
There's also Rotor...
tommieb75
tommieb75
@Jörg, thanks, java reference removed. :D
CrazyJugglerDrummer
+1  A: 

Another area of use is for iPhone app development (and I believe iPad now as well) via MonoTouch.

What is MonoTouch?

MonoTouch allows developers to create C# and .NET based applications that run on Apple's iPhone and Apple's iPod Touch devices, while taking advantage of the iPhone APIs and reusing both code and libraries that have been built for .NET, as well as existing skills.

Roughly speaking, it goes like this:

MonoTouch -> MonoDevelop/C# -> write an iPhone app -> compiled to native code -> iPhone app.

Relevant links:

Ahmad Mageed
It is not really a C# code per se, as it gets translated into objective c to be compiled...
tommieb75
@tommieb75 true, but it still fits within the OP's question and it doesn't require developers to write Objective-C. They are writing C# (even LINQ is supported to a certain extent).
Ahmad Mageed
@Ahmad: Ah cool... ok then... :)
tommieb75
@tommieb75 - see http://stackoverflow.com/questions/1453355/how-monotouch-works/1454068#1454068
Marc Gravell
A: 

You can use it on iPod apps if you use MonoTouch.

Esteban Araya
+1  A: 

Note that Unity 3D also allows "C# Scripts", and compiles to target Mac, Windows, Web, Wii and iPhone (and therefore iPad).

whybird
For the record: note that with the recent release of the iPhone OS version 4.0 SDK, Apple have outlawed using all forms of using cross-compiled languages on the iPhone OS family of devices.
whybird