Download User Manual

Transcript
LSH – Lund SIMULA user’s manuals
C routine declaration
char **ArrS
Simula interface specification
value ArrS; text array ArrS;
At the call Simula allocates space for the NULL-terminated array and all the
strings (again NULL-terminated) in C space. It is up to the called C-routine to
free these data-structures after use, or the call will leak memory. In this case
call-by-name is not supported.
8.8
C-routines as parameters to C-routines
C-routines that require a routine as a parameter can be specified, but the actual
parameter can only be another C-routine. The parameter must be specified ’callby-name’.
C routine declaration
*Cfunc()
Simula interface specification
name Cfunc; <type> procedure Cfunc;
Example:
external C procedure foo is
long real procedure foo(x,y); long real z,y;;
external C procedure Integrate is
long real procedure Integrate(a,b,step,f);
name f; ! a C-function must be used at call.;
long real a,b,step;
long real procedure f;
Use:
long real Result;
Result:=Integrate(1, 10, 0.001, foo);
8.9
C-struct as input and output parameters to C-routines
Many C-routines expect an address of a C-struct as one of its parameters. A
struct is an area of memory with a specified layout. Such a structure can be
emulated in Simula by using an integer array of the proper size or a text.
Depending on the layout of the actual C struct one or the other might be more
convenient to use. We are not using Simula class objects for this purpose since
the mapping from the declaration of a class, to the actual memory layout is nontrivial.
C routine declaration
rec1 *Struct1
rec2 *Struct2
Simula interface specification
name rec1; integer array rec1;
name rec2; text rec2;
When using an array, integer elements of the struct can be accessed as normal. Elements of other types in the struct (character, 16-bit short, real, long real)
can be mapped to ’integer’ by the routines (such as ItoSS, ItoR, IItoL) in class
UnsafeConversion in simlib.
18