# V2612. MISRA. Array element should not be initialized more than once.

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 is classified as:

MISRA-C-2012-9.4 MISRA-C-2023-9.4