Main Content

Specify Comment Style for C/C++ Code

If you have an Embedded Coder®, you can specify the comment style for C/C++ code generated from MATLAB® code. Specify single-line style to generate single-line comments preceded by //. Specify multiline style to generate single-line or multiline comments delimited by /* and */. Single-line style is the default for C++ code generation. Multiline style is the default for C code generation. For C code generation, select single-line comment style only if your compiler supports it.

Specify Comment Style Using the MATLAB Coder App

  1. On the Generate Code page, to open the Generate dialog box, click the Generate arrow .

  2. Set Build type to one of the following:

    • Source Code

    • Static Library (.lib)

    • Dynamic Library (.dll)

    • Executable (.exe)

  3. Click More Settings.

  4. On the Code Appearance tab, select the Include comments check box if it is not already selected. By default, the Include comments check box is selected.

  5. Set Comment Style to one of the following options.

    ValueDescription
    Auto(Use standard comment style of the target language)For C, generate multiline comments. For C++, generate single-line comments. (default)
    Single-line (Use C++-style comments)Generate single-line comments preceded by //.
    Multi-line (Use C-style comments)Generate single-line or multiline comments delimited by /* and */.

Specify Comment Style Using the Command-Line Interface

  1. Create a code configuration object for C/C++ code generation. For example, create a configuration object for C/C++ static library generation:

    cfg = coder.config('lib','ecoder',true);

  2. Set the CommentStyle property to one of the following values:

    ValueDescription
    'Auto' For C, generate multiline comments. For C++, generate single-line comments. (default)
    'Single-line'Generate single-line comments preceded by //.
    'Multi-line'Generate single-line or multiline comments delimited by /* and */.

    For example, this code sets the comment style to single-line style:

    cfg.CommentStyle='Single-line';

See Also

Related Topics