MISRA C:2012 Rule 8.15
All declarations of an object with an explicit alignment specification shall specify the same alignment
Since R2024a
Description
Rule Definition
All declarations of an object with an explicit alignment specification shall specify the same alignment.
This rule comes from MISRA C™: 2012 Amendment 3.
Rationale
It is undefined behavior to have multiple declarations of an object where the declarations have conflicting alignment specifications:
If you need to explicitly specify the alignment of an object using
_Alignas
, specify the same alignment for all declarations of that object.If you do not need to specify the alignment of an object, do not use
_Alignas
in any declaration of that object.
You use explicit alignment specifications in declarations and definitions to optimize code execution by, for example, matching the memory alignment requirements of a hardware interface or of a single instruction, multiple data (SIMD) operation.
Polyspace Implementation
The coding rule checker reports a violation of this rule for multiple declarations of the same variable with conflicting alignment specifications.
Polyspace® does not check structure declarations for compliance with this rule.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declarations and definitions |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2024a