Example of a Simple C ANYPARM Procedure [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
Example of a Simple C ANYPARM Procedure
This section contains a C procedure that can be called from HP Business
BASIC/XL using the ANYPARM call interface. This procedure shows how to
define the actual parameter table that the ANYPARM call requires. It
also contains an example procedure that accepts the actual parameter
table as a formal parameter.
#define C_MAX_NUM_PARAMETERS 50
#define C_SINTEGER_TYPE 5 /* identifies BASIC SHORT INTEGER type */
#define C_INTEGER_TYPE 11 /* identifies BASIC INTEGER type */
union u_scalar_value{ /* union to access parameter appropriately */
short sinteger_value;
int integer_value;
} scalar_value;
struct parameter_record{ /* entry in the actual parameter array */
union u_scalar_value *param_address;
short param_type;
short number_of_dimensions;
};
/* simple_example
simple_example is a procedure written to be called by the BASIC ANYPARM
call mechanism. A loop prints the values of scalar 16 and 32 bit integers
and prints error messages for all other entries in the actual parameter
table.
*/
simple_example(num_params, p_actual_param_table)
int num_params;
struct parameter_record p_actual_param_table[];
{
int param_index;
printf("Number of parameters passed to SIMPLE EXAMPLE is:%3d\n",
num_params);
if (num_params > C_MAX_NUM_PARAMETERS) {
printf("Too many actual parameters passed to SIMPLE EXAMPLE.\n");
printf("Maximum number is: %d\n", C_MAX_NUM_PARAMETERS);
exit(0);
}
for (param_index = 0; param_index < num_params; param_index++){
printf("%3d ", (param_index+1));
if (p_actual_param_table[param_index].number_of_dimensions == 0){
switch (p_actual_param_table[param_index].param_type){
case C_SINTEGER_TYPE:
printf("SHORT INTEGER %d\n", (*p_actual_param_table[param_index].
param_address).sinteger_value);
break;
case C_INTEGER_TYPE:
printf("INTEGER %d\n", (*p_actual_param_table[param_index].
param_address).integer_value
);
break;
default:
printf("Actual parameter to SIMPLE EXAMPLE has an invalid");
printf(" data type.\n");
}
} else {
printf("Actual parameter to SIMPLE EXAMPLE must be a scalar.\n");
}
}
}
Calling the C External SIMPLE_EXAMPLE
Assume that the C program presented in the previous section is in the
file, CPROG. To add the SIMPLE_EXAMPLE procedure to the local executable
library named XL, do the following:
:ccxl cprog
:linkeditor
linked>buildxl xl
linked>addxl from=$oldpass; to=xl
linked>exit
:
The output from the C procedure is the same as that from the Pascal
procedure in the previous section.
MPE/iX 5.0 Documentation