Extending the language / C-Extensions |
To make your C functions visible to the runtime system, you must define all the functions in the C interface file.
The C interface file is a C source file that defines the usrFunctions array. This array defines C functions that can be called from programs.
The last record of the usrFunctions array must be a line with all the elements set to NULL/0, to define the end of the list.
You typically do a forward declaration of your C functions, before the usrFunctions array initializer:
#include "f2c/fglExt.h" int c_init(int); int c_set_trace(int); int c_get_message(int); UsrFunction usrFunctions[]={ { "init", c_init, 0, 0 }, { "set_trace", c_set_trace, 1, 0 }, { "get_message", c_get_message, 1, 1 }, { NULL, NULL, 0, 0 } };
/* Avoids C compiler warnings because of un-initialized structure members */ UsrFunction usrFunctions[]={ { "init", c_init, 0, 0, 0 }, /* member for internal use ---^ */ ...