Main Content

Modeling Style

hisl_0032: Model object names

ID: Titlehisl_0032: Model object names
Description

For the following model object names:

  • Signals

  • Parameters

  • Blocks

  • Named Stateflow® objects (States, Boxes, Simulink® Functions, Graphical Functions, Truth Tables)

Use:

  • These characters: a-z, A-Z, 0-9, and the underscore (_).

  • Strings that are fewer than 32 characters.

Do not:

  • Start the name with a number.

  • Use underscores at the beginning or end of a string.

  • Use more than one consecutive underscore.

  • Use reserved identifiers.

Notes

Reserved names:

  • MATLAB® keywords

  • Reserved keywords for C, C++, and code generation. For complete list, see Reserved Keywords (Simulink Coder).

  • int8 , uint8

  • int16, uint16

  • int32, uint32

  • inf, Inf

  • NaN, nan

  • eps

  • intmin, intmax

  • realmin, realmax

  • pi

  • infinity

  • Nil

Rationale
  • Readability

  • Compiler limitations

  • Model-to-generated code traceability

Model Advisor ChecksCheck model object names (Simulink Check)
See Also

MAB guidelines:

References

  • MISRA C:2012, Rule 21.2

  • ISO 26262-6, Table 1 (1h) 'Use of naming conventions'

Last ChangedR2018b
Example

Recommended

  • Block name: My_Controller

  • Signal name: a_b

Not Recommended

  • Block name: My Controller

  • Signal name: 12a__b

hisl_0061: Unique identifiers for clarity

ID: Titlehisl_0061: Unique identifiers for clarity
DescriptionWhen developing a model:
AUse unique identifiers for Simulink signals.
BDefine unique identifiers across multiple scopes within a chart.
NotesThe code generator resolves conflicts between identifiers so that symbols in the generated code are unique. The process is called name mangling.
RationaleA, BImprove readability of a graphical model and mapping between identifiers in the model and generated code.
Model Advisor CheckCheck Stateflow charts for uniquely defined data objects (Simulink Check)
References
  • DO-331, Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • IEC 61508-3, Table A.3 (2) ‘Strongly typed programming language’
    IEC 61508-3, Table A.3 (3) - Language subset
    IEC 61508-3, Table A.4 (5) - Design and coding standards

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) - 'Use of language subsets'
    ISO 26262-6, Table 1 (1c) 'Enforcement of strong typing'
    ISO 26262-6, Table 1 (1d) - 'Use of defensive implementation techniques'
    ISO 26262-6, Table 1 (1e) - 'Use of well-trusted design principles'
    ISO 26262-6, Table 1 (1f) - 'Use of unambiguous graphical representation'
    ISO 26262-6, Table 1 (1g) - 'Use of style guides'
    ISO 26262-6, Table 1 (1h) - 'Use of naming conventions'

  • EN 50128, Table A.3 (1) - Defensive Programming
    EN 50128, Table A.4 (8) 'Strongly Typed Programming Language'
    EN 50128, Table A.4 (11) - 'Language Subset'
    EN 50128, Table A.12 (1) 'Coding Standard'
    EN 50128, Table A.12 (2) 'Coding Style Guide'

See Also Code Appearance (Simulink Coder)
Last ChangedR2017b
Examples

Not Recommended

In the following example, two states Scope_1 and Scope_2 use local identifier IntCounter.

The identifier IntCounter is defined for two states, Scope_1 and Scope_2.

Recommended

To clarify the model, create unique identifiers. In the following example, state Scope_1 uses local identifier IntCounter_Scope_1. State Scope_2 uses local identifier IntCounter_Scope_2.

The identifier IntCounter_Scope_1 is defined for state Scope_1. Identifier IntCounter_Scope_2 is defined for Scope_2.

hisl_0062: Global variables in graphical functions

ID: Titlehisl_0062: Global variables in graphical functions
Description

For data with a global scope used in a function, do not use the data in the calling expression if a value is assigned to the data in that function.

RationaleEnhance readability of a model by removing ambiguity in the values of global variables.
Model Advisor ChecksCheck global variables in graphical functions (Simulink Check)
References
  • IEC 61508–3, Table A.3 (3) 'Language subset'
    IEC 61508–3, Table A.4 (4) 'Modular approach'
    IEC 61508–3, A.4 (5) 'Design and coding standards'

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) 'Use of language subsets'
    ISO 26262-6, Table 1 (1f) 'Use of unambiguous graphical representation'
    ISO 26262-6, Table 1 (1h) 'Use of naming conventions'

  • EN 50128, Table A.4 (11) 'Language Subset'
    EN 50128, Table A.12 (1) 'Coding Standard'
    EN 50128, Table A.12 (2) 'Coding Style Guide'

  • DO-331, Section MB.6.3.2.g 'Algorithms are accurate'

  • MISRA C:2012, Rule 13.2
    MISRA C:2012, Rule 13.5

Last ChangedR2018b
Examples

Consider a graphical function graphicalFunction that modifies the global data G.

Recommended

Not Recommended