Are there any means of converting C # to C?

I know that C # is different from the .NET Framework, C # is a programming language that is a standard of ECMA (ECMA-334) and ISO (ISO / IEC 23270).

I don't need a converter that converts ANY C # source code (including the .NET Framework) to C, but I need a tool that converts CMA ECMA standard source code to ANSI C source code.

Something like java2c , but for ECMA C #.

+7
source share
3 answers

There is no such thing, but the Vala programming language can use source code very similar to C # and generate C code or compile it directly.

http://live.gnome.org/Vala

Of course, the only problem is libraries: C # has many APIs that you will have to provide or modify the source code to adapt to the standard Vala library.

If you want to translate this code into C because you need to compile it, there are other possibilities.

For example, ngen in the microsoft world:

http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.80).aspx

In a monoproject, you can create one exe file using the interpreter and libraries. Find mkbundle:

http://www.mono-project.com/Mono:Runtime

Mono can compile "ahead of time", i.e. generate your own code before the program is executed, so it will run faster.

http://www.mono-project.com/Mono:Runtime#Ahead-of-time_compilation

+4
source

As a proof of concept, I wrote a tool called a universal transporter that converts a small subset of C # to C and several other languages.

For example, it can translate this function from C # to C:

public static double distance_formula(double x1,double y1,double x2,double y2){ return Math.Sqrt(Math.Pow(x1-x2,2)+Math.Pow(y2-y1,2)); } 

This is the equivalent C code that the translator will generate:

 double distance_formula(double x1,double y1,double x2,double y2){ return sqrt(pow(x1-x2,2)+pow(y2-y1,2)); } 

I did not find any other C # -to-C compilers, but there is a C # -to-Lua compiler that could be combined with the Lua-to-C compiler to generate C source code.

It is also possible to compile C # to WebAssembly using the Blazor compiler , and then decompile it into C source code using wasm2c .

+1
source

Depends on what you mean. If you mean "Is it possible to convert C # to readable and maintainable C code?", Then sorry, the answer is no - C # functions are not directly displayed in C.

0
source

Source: https://habr.com/ru/post/903105/


All Articles