Sometimes it is needed to write a module in C, for instance to interface to a library which is not available for Orca, but is available for C. If this module is called modnam, the user must write a specification module modnam.spf which contains Orca specifications for all functions that the user wants to write in C. The oc program will compile this specification, because it detects that there is no corresponding module implementation in Orca. It will produce a modnam.c and a modnam.h file for it.
The user must of course also provide the C implementation of these functions. These must reside in a .c file (with a different name!) that must start with
Each function f must have a corresponding implementation in C with the name#include <interface.h>
#include "modnam.h"
If the function does not return a value, or it returns a complex type, it must be declared void. If it returns a simple type, the following table indicates which type to use for each simple Orca type.f_modnam__f
Orca type C type usual C implementation shortint t_shortintshortinteger t_integerintlongint t_longintlongshortreal t_shortrealfloatreal t_realdoublelongreal t_longrealdoublechar t_charunsigned charenum t_enumunsigned charboolean t_booleanunsigned char
OUT or SHARED parameters are passed by reference (an address is passed), IN parameters are passed by value if they have a simple type, otherwise they are passed by reference as well. (This means that the user has to be careful not to change IN parameters.) In addition, if the function returns a complex type, a parameter should be added as if it is an OUT parameter.
As a small example, if the user wants to use the exp function of C, he could have the following specification module math.spf:
MODULE SPECIFICATION math;
FUNCTION exp(x: REAL): REAL;
END;
and the following exp.c file:
#include <interface.h>
#include "math.h"
double exp(double);
t_real f_math__exp(t_real x)
{
return (t_real) exp((double) x);
}
The user should also explicitly add exp.c to the list of files offered to oc.