MATLAB to C++ Data Type Mapping

The following table shows how MATLAB® data types correspond to fixed-width C++ types.

Fixed-Width Data Types

C Exact-Width Integer TypesEquivalent MATLAB Type

int8_t

int8

uint8_t

uint8

int16_t

int16

uint16_t

uint16

int32_t

int32

uint32_t

uint32

int64_t

int64

uint64_t

uint64

C Floating Point TypesEquivalent MATLAB Type

float

single

double

double

Other C TypesEquivalent MATLAB Type

bool

logical

Non-Fixed-Width Integer Types

MATLAB maps non-fixed-width types to the corresponding fixed-width C types, based on the compiler used.

MATLAB supports the following non-fixed-width C integer types.

  • short

  • short int

  • signed short

  • signed short int

  • unsigned short

  • unsigned short int

  • int

  • signed int

  • unsigned

  • unsigned int

  • long

  • signed long

  • signed long int

  • unsigned long

  • unsigned long int

  • long long

String and Character Types

The following table shows how MATLAB converts string and char data returned from C++ into MATLAB types.

C++ String and Character Types

C++ Character TypesEquivalent MATLAB Type

char

int8
const char *

signed char

int8

unsigned char

uint8

C++ String TypesEquivalent MATLAB Type

std::string

string, ASCII characters only

const char *

string

User-Defined Types

C++ User-Defined TypesEquivalent MATLAB Type

struct StructName

libname.StructName

enum EnumName

libname.EnumName

nullptr Return Types

The C++ interface returns type-specific empty values for functions that return nullptr.

  • For type double,​ MATLAB returns[] for the value double.empty.

  • For all other fundamental types,​ MATLAB returns an MLTYPE.empty value. To determine MLTYPE, look for the C or C++ type in the tables in this topic. MLTYPE is in the Equivalent MATLAB Types column.

    To test for nullptr types, call the isempty function.

  • For non-fundamental types,​ MATLAB returns a nullptr object. To test for nullptr objects, call the clibIsNull function.

Unsupported Data Types

If the data type of an argument to a class constructor, method, or function is one of these types, or if the library contains any unsupported language features, then the functionality is not included in the MATLAB interface to the library.

  • wchar_t

  • char16_t

  • char32_t

  • Any type with a size greater than 64 bits, for example, long double

  • void *

  • union

  • Pointers or arrays of std::string

  • Pointers or references to enumerations

  • Pointer, array, and reference data members

  • std smart pointers other than std::shared_ptr

  • Static data members

  • Multilevel pointers, such as type** and type***

  • Function pointer

  • Class templates with incomplete or no instantiations

Messages About Unsupported Types

MATLAB reports on constructs that use unsupported types. To view these messages, use the 'Verbose' option in the clibgen.generateLibraryDefinition or clibgen.buildInterface functions.

For example, suppose that functionName in ClassName is defined in HeaderFile.h. If an argument to functionName is of type wchar_t, then MATLAB does not add functionName to the definition file. In addition, if 'Verbose' is true, then clibgen.generateLibraryDefinition displays the following message.

Did not add member 'functionName' to class 'ClassName' at HeaderFile.h:290.
  'wchar_t' is not a supported type.

See Also

|