2

I am looking for an option to compile C# syntax to native code (or maybe to C++?). I am not interested in having all the libraries that are officially part of the language, just being able to write programs the same as I write my C++ programs, but using language constructs such as partial classes, properties, lambdas, generics, etc.

  1. Is there such a thing?
  2. If there isn't, is such a thing even possible, or am I misunderstanding something fundamental about C#?
4
  • 3
    If you read the C# spec, some language feature are tied in to the BCL. You can't completely decouple them (say IDisposable and the using statement). Commented Dec 29, 2011 at 13:53
  • C# compiles to intermediate language, which is then executed by the .NET virtual machine. There are no libraries 'part of the language', the libraries provided by .NET are part of the BCL/FCL and are standardized by ISO. Commented Dec 29, 2011 at 13:54
  • @knittl I meant without (most of) the standard libraries. I assume minimal things like Array and String can be included without having to write the whole BCL/FCL/CLR/whatever it is called. Commented Dec 29, 2011 at 14:25
  • @Oded you can't decouple from the BCL, but you can in theory replace the BCL. You can remove the reference to mscorlib when you compile, and then you become responsible for providing certain required types, such as Object, Type, Array, String, etc. Also, the using statement is a compiler construct; it has nothing to do with the BCL. Commented Dec 29, 2011 at 14:54

3 Answers 3

6

Possibly the closest thing to what you want is the Vala programming language. It is heavily inspired by C# and compiles to C, which is then compiled by a traditional C compiler.

It has partial classes, properties, lambdas, generics, etc, as you say, but it's not C#.

Also check out IL2CPU which translates IL to machine code. Maybe it can be used on .NET assemblies.

Sign up to request clarification or add additional context in comments.

1 Comment

Re: IL2CPU, you can use the mono runtime (mkbundle or mono --aot) to precompile into native images that don't depend on a CLR or runtime.
0

perhaps

NGen.exe

see

3 Comments

This just pre-compiles the byte code. It doesn't create s stand-alone .exe that can be run without the framework.
@baruch - Why would you write C# code that doesn't require the Framework. Just use C/C++ at that point.
@Ramhound Since the language has many useful features. I listed a few of them in the question.
0

The standard csc.exe compiler can compile without using the BCL. See the reference for the /nostdlib switch: http://msdn.microsoft.com/en-us/library/fa13yay7.aspx

In part, it says:

"Use this option if you want to define or create your own System namespace and objects."

Silverlight projects use this, for example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.