Any type of parameter can be passed to external functions. While using simple data types is easy, handling arrays and structured data types requires knowledge about the alignment and size of the specific data types in use.
C Data Type | BDL Data Type |
---|---|
Char, unsigned char | Number |
Short, unsigned short | Number |
Long | Number |
Double | Float |
Float | Float |
Char* | String |
When a parameter is passed to a function by value, it is declared simply by specifying its type. If a parameter is passed by reference (for example, if it is used as an output parameter), a pointer to the data type must be defined.
The example below illustrates how function parameters are declared in C and how corresponding external functions must be declared in BDL. In addition, an example of an external function call is provided.
In this example, the external function T_PARAM receives the following input parameters: inChar, inShort, inLong, inDouble, inFloat, inUShort, and inUChar. A corresponding output parameter belongs to each: outChar, outShort, outLong, outDouble, outFloat, outUShort, and outUChar. These parameters must be declared as pointers because during function calls references to the variables are passed to the functions. Additionally, a string called inoutString is declared as an input and output parameter.
char* T_PARAM( char inChar, // in short inShort, long inLong, double inDouble, float inFloat, unsigned short inUShort, unsigned char inUChar, char* inoutString, // in/out char* outChar, // out short* outShort, long* outLong, double* outDouble, float* outFloat, unsigned short* outUShort, unsigned char* outUChar ) { char sBuffer[1000]; // copy the values of the input parameters to the // output parameters and the return value return sBuffer; }
To use the above-defined T_PARAM function in BDL, the function must be declared in the external functions section of a Silk Performer script. This is illustrated in the example below. In this case, the parameters are defined as formal data types. The comments attached to each parameter indicate the corresponding BDL data type.
"T_PARAM" function t_param( in char, // in number in short, // in number in long, // in number in double, // in float in float, // in float in unsigned short, // in number in unsigned char, // in number inout string, // inout string out char, // out number out short, // out number out long, // out number out double, // out float out float, // out float out unsigned short, // out number out unsigned char): string(100); // out number
The following example illustrates how to call the T_PARAM function. In this example, random values are assigned to the variables and passed to the function as input parameters.
dcltrans transaction TMain var n1, n2, n3, n4, n5, n6, n7, n8, n9, n10 : number; f1, f2, f3, f4 : float; s1, sRet : string; begin n1 := 127; n2 := 32000; n3 := 2000000; n4 := 64000; n5 := 255; f1 := 12345.12345; f2 := 12.99; s1 := "Teststring"; sRet := t_param(n1, n2, n3, f1, f2, n4, n5, s1, n6, n7, n8, f3, f4, n9, n10); end TMain;