The `addPrototypes` action from the `fcmpact` action set allows for the dynamic definition and registration of external function prototypes within a CAS session. These prototypes, defined using the PROTO statement, are then stored in a specified CAS table, making them available for use in other CASL programs or actions. This is particularly useful for integrating external C/C++ functions into the CAS environment without pre-compilation into a library.
| Parameter | Description |
|---|---|
| bridgeCatchSignals | Specifies that the bridge file should contain code to install and handle signals. Default: FALSE. |
| bridgeFile | Specifies the path to the PROTO bridge file source module. |
| encode | Specifies that the prototype definitions are encoded in the saved function table. Aliases: encrypt, hide. Default: FALSE. |
| funcTable | Specifies the output table where the PROTO definitions are written. This is a required parameter. |
| library | Specifies an existing FCMP library to load. |
| package | Specifies the FCMP package name used for storing PROTO definitions. |
| routineCode | Specifies the PROTO definition's code that is saved to the table. This is a required parameter. Alias: code. |
| saveTable | Specifies if the FCMP table should be saved to disk. Default: FALSE. |
| stdcall | Specifies that functions should be called using the __stdcall convention (Windows PC only). Default: FALSE. |
The `addPrototypes` action does not create a standard dataset. Instead, it populates a special CAS table with function prototype definitions, making them accessible within the CAS session. The following code demonstrates how to set up the action, but it does not generate a dataset in the traditional sense.
| 1 | /* This action does not create |
| 2 | data directly. See examples below. */ |
This example defines a single external C function prototype named `mycfunc` and stores it in a CAS table named `myprotos` within the `casuser` caslib.
| 1 | PROC CAS; |
| 2 | fcmpact.addPrototypes |
| 3 | routineCode={"proto mycfunc(double) returns double;"}, |
| 4 | funcTable={name="myprotos", caslib="casuser", replace=true}; |
| 5 | QUIT; |
This example defines two prototypes for external C functions, `c_sum` and `c_multiply`. It groups them into a package named `myExternalTools`, encodes the definitions for security, and saves the resulting table `myprotos` permanently in the `casuser` caslib.
| 1 | PROC CAS; |
| 2 | fcmpact.addPrototypes |
| 3 | routineCode={ |
| 4 | "proto c_sum(double, double) returns double;", |
| 5 | "proto c_multiply(double, double) returns double;" |
| 6 | }, |
| 7 | package="myExternalTools", |
| 8 | encode=true, |
| 9 | saveTable=true, |
| 10 | funcTable={name="myprotos", caslib="casuser", replace=true}; |
| 11 | QUIT; |
This example demonstrates how to generate a C bridge file. This file contains the necessary C code to link your external functions with the SAS FCMP environment. The `bridgeFile` parameter specifies the path where the C source file will be created.
| 1 | PROC CAS; |
| 2 | fcmpact.addPrototypes |
| 3 | routineCode={"proto my_c_function(double) returns double;"}, |
| 4 | package="mycpackage", |
| 5 | bridgeFile="/cas/data/mycfuncs.c", |
| 6 | funcTable={name="myprotos", caslib="casuser", replace=true}; |
| 7 | QUIT; |
A financial institution needs to integrate its proprietary, high-performance C-based risk calculation algorithms into its SAS Viya environment. This scenario tests the basic reg...
A research institute is migrating a large library of proprietary C functions for genomic sequence analysis to SAS Viya. This test validates the action's ability to handle a larg...
An engineering team is integrating a legacy C simulation library that is known to be unstable and can cause segmentation faults. They need to use the `addPrototypes` action to g...