Main Content

Static array container type

Container type for static arrays

Since R2020a

Model Configuration Pane: Code Generation / Code Style

Description

Specify a container type for static arrays in the generated code. Choose either C-style array or std::array.

Dependencies

To enable this parameter, set Language to C++ and set Code interface packaging to C++ class.

Settings

C-style array (default) | std::array

Default: C-style array

C-style array

The code generator generates array containers by using C-style arrays.

std::array

std::array is a template class that represents fixed-size arrays. If you choose this option, the code generator generates array containers by using std::array.

If the generated code contains multidimensional arrays, the code generator does not honor the std::array container type for arrays of more than one dimension.

Examples

expand all

Consider this model, myModel:

Model that passes a signal from an Inport block to an Outport block.

The model passes a 1-dimensional signal of length 5 from an Inport block to an Outport block. If you set the Static array container type model configuration parameter to C-style array, the code generator produces this code in myModel.h:

// External inputs (root inport signals with default storage)
struct ExtU_myModel_T {
  real_T Inport[5];                  // '<Root>/Inport'
};

// External outputs (root outports fed by signals with default storage)
struct ExtY_myModel_T {
  real_T Output[5];                  // '<Root>/Output'
};
If you set the Static array container type model configuration parameter to std::array, the code generator produces this code instead:
// External inputs (root inport signals with default storage)
struct ExtU_myModel_T {
  std::array<real_T, 5> Inport;      // '<Root>/Inport'
};

// External outputs (root outports fed by signals with default storage)
struct ExtY_myModel_T {
  std::array<real_T, 5> Output;      // '<Root>/Output'
};

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo recommendation

Programmatic Use

Parameter: ArrayContainerType
Type: character vector
Value: 'C-style array' |'std::array'
Default: 'C-style array'

Limitations

  • This parameter does not affect static arrays in function interfaces. If a generated function takes a fixed-size array as an argument or returns a fixed-size array, the code generator generates that array as a C-style array regardless of the setting of this parameter.

Version History

Introduced in R2020a

expand all