External Interfaces Previous page   Next Page

Primitive Types

All standard scalar C data types are supported by the shared library interface. These are shown in the two tables below along with their equivalent MATLAB types. MATLAB uses the type from the right column for arguments having the C type shown in the left column.

(The second table shows extended MATLAB types in the right column. These are instances of the MATLAB lib.pointer class rather than standard MATLAB data types. See Creating References for information on the lib.pointer class.)

C Type (on a 32-bit computer)
Equivalent MATLAB Type
char, byte
unsigned char, byte
unsigned short
int, long
unsigned int, unsigned long
char *
string (1xn char array)

C Type (on a 32-bit computer)
Extended MATLAB Type
integer pointer types (int *)
float *
double *
mxArray *
MATLAB array
void *
type **
Same as typePtr with an added Ptr (e.g., double **
is doublePtrPtr)

Converting to Other Primitive Types

For primitive types, MATLAB automatically converts any argument to the data type expected by the external function. This means that you can pass a double to a function that expects to receive a byte (8-bit integer) and MATLAB does the conversion for you.

For example, the C function shown here takes arguments that are of types short, int, and double:

You can simply pass all of the arguments as type double from MATLAB. MATLAB determines what type of data is expected for each argument and performs the appropriate conversions:

Converting to a Reference

MATLAB also automatically converts an argument passed by value into an argument passed by reference when the external function prototype defines the argument as a reference. So a MATLAB double argument passed to a function that expects double * is converted to a double reference by MATLAB.

addDoubleRef is a C function that takes an argument of type double *:

Call the function with three arguments of type double, and MATLAB handles the conversion:


For arguments that require char *, you can pass a MATLAB string (i.e., character array).

This C function takes a char * input argument:

libfunctions shows that you can use a MATLAB string for this input.

Create a MATLAB character array, str, and pass it as the input argument:

Previous page  Data Conversion Enumerated Types Next page

© 1994-2005 The MathWorks, Inc.