Calling C Functions - LucasMW/mongaComp GitHub Wiki
Calling C Functions
Monga can use C functions.
These functions must be declared in monga, and defined in C.
Standard C functions can be used by simply be declared:
int exit(int number); //will render C exit usable
You can also use your own C functions, for example
char[] readFile(char[] filename); // monga source
//(...)
char[] fileStr;
fileStr = readFile("input.txt");
In C this function its something like this
char * readFile(char* path)
{
int size;
FILE * input;
char * fileString;
//(...)
return fileString;
}
However, in order to be used in monga, these C functions must be able to be declared in monga
Anything that uses void* , structured types or elipses cannot be declared in monga.
Some notable examples are printf(), scanf(), fprintf() and fscanf().
Note that you will need clang to compile C functions to LLVM to use this feature, since MongaComp isn't a C compiler.