Extending the language / C-Extensions |
With C-Extensions you can call C functions from the program in the same way that you call normal functions.
int function-name( int )
function-name must be written in lowercase letters. The fglcomp compiler converts all .4gl module functions names to lowercase.
The C function must be declared in the usrFunctions array in the C interface file.
In the next code example, the C-Extension module "ext1.c" defines the c_fct() function. The C-Extension library is imported by the 4gl module with IMPORT:
#include <stdio.h> #include <f2c/fglExt.h> int c_fct( int n ) { int r1, r2; if (n != 2) ... error ... popint(&r1); popint(&r2); pushint(r1+r2); return 1; }
Genero module calling the C function:
IMPORT ext1 MAIN LET x = c_fct(15, 20) END MAIN