PROTO Procedure

Interfacing with External C Functions

To make it easier to interface with external C functions, many PROTO-compatible procedures have been enhanced to support most of these C types.
There is no way to return and save a pointer to any type in a SAS variable (see Automatic Type Casting for the short Data Type in an Assignment Statement.) Pointers are always dereferenced, and their contents are converted and copied to SAS variables.
The EXTERNC statement is used to specify C variables in PROTO compatible procedures. The syntax of the EXTERNC statement has the following form:
EXTERNC DOUBLE | INT | LONG | SHORT | CHAR <[*][*]> var-1 <var-2 ... var-n>;
The following table shows how these variables are treated when they are positioned on the left side of an expression. The table shows the automatic casting that is performed for a short type on the right side of an assignment. (Explicit type conversions can be forced in any expression, with a unary operator called a cast.) The table lists all the allowed combinations of short types that are associated with SAS variables.
Note: A table for int, long, and double types can be created by substituting any of these types for “short” in this table.
If any of the pointers are null and require dereferencing, then the result is set to missing if there is a missing value set for the result variable. For more information, see MAPMISS Statement.
Automatic Type Casting for the short Data Type in an Assignment Statement
Type for Left Side of Assignment
Type for Right Side of Assignment
Cast Performed
short
SAS numeric
y = (short) x
short
short
y = x
short
short *
y = * x
short
short **
y = ** x
short *
SAS numeric
* y = (short) x
short *
short
y = & x
short *
short *
y = x
short *
short **
y = * x
short **
SAS numeric
**y = (short) x
short **
short *
y = & x
short **
short **
y = x
SAS numeric
short
y = (double) x
SAS numeric
short *
y = (double) * x
SAS numeric
short **
y = (double) ** x
The following table shows how these variables are treated when they are passed as arguments to an external C function.
Types That Are Allowed for External C Arguments
Function Prototype
SAS Variable Type
C Variable Type
short
numeric
short, short *, short **
short *
numeric, array
short, short *, short **
short **
array
short *, short **
int
numeric
int, int *, int **
int *
numeric, array
int, int *, int **
int **
array
int *, int **
long
numeric
long, long *, long **
long *
numeric, array
long, long *, long **
long **
array
long *, long **
double
numeric
double, double *, double **
double *
numeric, array
double, double *, double **
double **
array
double *, double **
char *
character
char *, char **
char **
character
char *, char **
struct *
structure
struct *, struct **
struct **
structure
struct *, struct **
Note: Automatic conversion between two different C types is never performed.