Closed ghost closed 1 year ago
Duplicate of #73
Duplicate of #73
Yup. Duplicate. But do you have any progress since then? The last reply was from 2022. Did the OP on that thread suggest any solutions nor workarounds like me? Nope. He only raised the problem. And my issue is about C/C++ exclusively, not as broad as his issue, please note.
Fusion is a language for authoring libraries, not command-line programs. Libraries do not have main
. Why would you need main
generated from your Fusion code?
There's a trivial workaround, simply link with this C code:
#include "myfusionlib.h"
int main(int argc, char **argv)
{
MyFusionClass_Main(argc, argv);
}
For example, this Fusion code correctly translated to C# and Java:
public static void Main(string[] args)
But it doesn't work for C/C++.
I tried a main function without parameters:
It translated to
void Test_main(void)
in C andvoid Test::main()
in C++.I suggest treating the
Main
function as a special function if translating to target C/C++. It should be put outside of any classes or structs in the generated code.I also suggest Fusion to correctly translate this
Main
function to C/C++:public static int Main(int argc, string[] argv)
It should correctly translate to
int main(int argc, char *argv[])
.Why I suggest using another
Main
function in Fusion code if translating to C/C++? Because thisMain
function will not correctly translate to C/C++:public static void Main(string[] args)
It's more optimized for C# and Java.
Following this discipline, we will have to write two
Main
function. One is specific to C/C++. One is for the rest. Conditional compilation will help. This is acceptable IMO.