MISRA C:2023 Rule 9.2
Description
Rule Definition
The initializer for an aggregate or union shall be enclosed in braces.
Rationale
The rule applies to both objects and subobjects. For example, when initializing a structure that contains an array, the values assigned to the structure must be enclosed in braces. Within these braces, the values assigned to the array must be enclosed in another pair of braces.
Enclosing initializers in braces improves clarity of code that contains complex data structures such as multidimensional arrays and arrays of structures.
Tip
To avoid nested braces for subobjects, use the syntax {0}
,
which sets all values to zero.
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: Initialization |
Category: Required |
AGC Category: Readability |
Version History
Introduced in R2024a