Main Content

Specify Data Types Used in Generated Code

MATLAB® Coder™ can use built-in C data types or predefined types from rtwtypes.h in generated code. By default, when the generated code declares variables, it uses built-in C types.

You can explicitly specify the data types used in generated code in the project settings dialog box or at the command line.

Specify Data Type Using the MATLAB Coder App

  1. To open the Generate dialog box, on the Generate Code page, click the Generate arrow .

  2. Set Build type to Source Code, Static Library, Dynamic Library, or Executable (depending on your requirements).

  3. Click More Settings.

  4. To use built-in C types, on the Code Appearance tab, set Data Type Replacement to Use built-in C data types in the generated code. To use predefined types from rtwtypes.h, set Data Type Replacement to Use MathWorks typedefs in the generated code.

Specify Data Type at the Command Line

  1. Create a configuration object for code generation. Use coder.config with arguments 'lib','dll', or 'exe' (depending on your requirements). For example:

    cfg = coder.config('lib');
  2. To use built-in C types, set the DataTypeReplacement property to 'CBuiltIn'.

    cfg.DataTypeReplacement = 'CBuiltIn';

    To use predefined types from rtwtypes.h, set the DataTypeReplacement property to 'CoderTypedefs'.