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 .
source share