Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2666. MISRA. All declarations of an...
menu mobile close menu
Additional information
toggle menu Contents

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

Nov 18 2025

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;