# V2666. MISRA. All declarations of an object with an explicit alignment specification should specify the same alignment.

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C.

If any declaration of an object contains an explicit alignment specifier (`alignas`), all other declarations of the same object should be defined with the same alignment.

If no alignment is specified, none of the declarations for this object should indicate it.

If declarations of the same object request different alignment requirements in different source code files, it leads to undefined behavior (C11, Section 6.7.5.6).

The example:

    //header.h
    extern alignas(16) int32_t var;

    //file.c
    alignas(8)         int32_t var;

In the `header.h` header file, the `var` variable is declared with alignment of 16 bytes. In the source file, the same variable is defined with a different alignment. This results in undefined behavior.

The fixed code:

    //header.h
    extern alignas(16) int32_t var;

    //file.c
    alignas(16)        int32_t var;

This diagnostic is classified as:

MISRA-C-2023-8.15