This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) guidelines for software development.
This rule applies only to C. The C language has special syntax to initialize expressions - a designated initializer. It allows you to initialize array or structure elements in a custom order.
For example, you can initialize an array's specific elements:
int arr[4] = {
[1] = 1,
[3] = 2,
};
This syntax also works for structures:
struct point
{
int x;
int y;
};
struct point pt1 = {
.x = 1,
.y = 1,
};
However, when using this syntax, a developer can make a mistake and initialize the same element twice:
int arr[4] = {
[3] = 1,
[3] = 2,
};
struct point pt1 = {
.x = 1,
.x = 1,
};
MISRA prohibits this syntax construction, because the language standard does not define whether the code above causes any side effects. Most likely, such mistakes are typos.
This diagnostic rule is classified as:
|
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: