Understanding C-Extensions

C-Extensions allow you to write custom shared libraries in the C language.

Using C-Extensions, C functions implemented in shared libraries can be called from the Genero application code. This feature allows you to extend the language with custom libraries, or existing standard libraries, by writing some 'wrapper functions' to interface with the Genero language.

On regular platforms, C-Extensions are implemented with shared libraries, that are loaded by the fglrun program on demand.


Platforms such as iOS mobile devices do not allow you to load shared libraries. In this case, you must re-link the virtual machine. For more details, see Implementing C-Extensions for GMI.

Function parameters and returned values are passed/returned on the runtime stack, using pop/push functions. Be sure to pop and push the exact number of parameters/returns expected by the caller; otherwise, a fatal stack error will be raised at runtime.

In order to use a C-Extension in your program, you typically specify the library name with the IMPORT instruction at the beginning of the module calling the C-Extension functions. The compiler can then check for the existence of the functions and the library will be automatically loaded at runtime.

  • The C code written in C-Extensions is usually platform specific, which does not ease the migration of your application to a different operating system, especially when doing a lot of system calls. Additionally, C data types are defined differently depending on the processor architecture (32 / 64 bits issues). This can also be an issue.
  • Make sure that the functions defined in your C-Extensions do not conflict with program functions. In case of conflict, you will get a compiler or a runtime error, depending on the loading technique used.