Specify Indent Style for C/C++ Code - MATLAB & Simulink (original) (raw)

Main Content

If you have an Embedded CoderĀ® license, you can control the indent style and indent size in C/C++ code generated from MATLABĀ® code. Indent style controls the placement of braces. Indent size controls the number of characters per indentation level.

You can specify the K&R indent style or the Allman indent style. Both styles:

The K&R style and the Allman style differ in their placement of the opening brace for a control statement. If you want the opening brace on the same line as its control statement, select the K&R style. Here is code that has the K&R indent style:

void addone(const double x[6], double z[6]) { int i; for (i = 0; i < 6; i++) { z[i] = x[i] + 1.0; } }

If you want the opening brace on its own line, select the Allman style. Here is code that has the Allman indent style:

void addone(const double x[6], double z[6]) { int i; for (i = 0; i < 6; i++) { z[i] = x[i] + 1.0; } }

Specify Indent Style Using the MATLAB Coder App

  1. Set Build type to one of the following:
    • Static Library (.lib)
    • Dynamic Library (.dll)
    • Executable (.exe)
  2. Click Settings.
  3. Set Indent style to K&R orAllman.
  4. Set Indent size to an integer from 2 to 8.

Specify Indent Style Using the Command-Line Interface

  1. Create a code configuration object for 'lib', 'dll', or 'exe'. For example:
    cfg = coder.config('lib','ecoder',true); % or dll or exe
  2. Set the IndentStyle property to 'K&R' or 'Allman'. For example:
    cfg.IndentStyle = 'Allman';
  3. Set the IndentSize property to an integer from 2 to 8. For example:

See Also

coder.EmbeddedCodeConfig

Topics