himl_0004: MATLAB Code Analyzer recommendations for code generation
R2026bUse MATLAB Code Analyzer with %#codegen directive and follow code
generation recommendations
Usage: High-Integrity System Modeling
Guideline ID: himl_0004
Rules
| himl_0004: MATLAB Code Analyzer recommendations for code generation | |
|---|---|
| A | To activate MATLAB® Code Analyzer messages for code generations, use the
Rationale In external
MATLAB functions, the Verification Check MATLAB Code Analyzer messages (Simulink Check) Example — Correct Activate MATLAB Code Analyzer messages for code generations: %#codegen
function y = function(u)
y = inc_u(u));
end
function yy = inc_u(uu)
yy = uu + 1;
end
Example — Incorrect External MATLAB file used in Simulink® with missing function y = function(u)
% nested functions can't be used for code generation
function yy = inc_u(uu)
yy = uu + 1;
end
y = inc_u(u));
end
|
| B | Review the MATLAB Code Analyzer messages. Either:
Rationale
Verification Check MATLAB Code Analyzer messages (Simulink Check) Example — Correct
Example — Incorrect
|
Tips
The MATLAB Code Analyzer messages provide identifies potential errors, problems, and opportunities for improvement in the code.
Industry Standards
IEC 61508-3, Table A.3 (3) 'Language subset'
IEC 61508-3, Table A.4 (3) 'Defensive programming'
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 (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.4 (11) 'Language Subset'
EN 50128, Table A.3 (1) 'Defensive Programming'
EN 50128, Table A.12 (1) 'Coding Standard'
EN 50128, Table A.12 (2) 'Coding Style Guide'EN 50657, Table A.4 (11) 'Language Subset'
EN 50657, Table A.3 (1) 'Defensive Programming'
EN 50657, Table A.12 (1) 'Coding Standard'
EN 50657, Table A.12 (2) 'Coding Style Guide'EN 50716, Table A.3 (1) 'Defensive Programming'
EN 50716, Table A.12 (1) 'Coding Standard'
EN 50716, Table A.12 (2) 'Coding Style Guide'DO-331, Section MB.6.3.1.b 'Accuracy and consistency'
DO-331, Section MB.6.3.2.b 'Accuracy and consistency'