Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The C Standard, 6.3.2.3, paragraph 7 [ISO/IEC 9899:2011], states:

A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the referenced type, the behavior is undefined.

...

This compliant solution uses the alignment specifier, which is new to C11, to declare the char object c with the same alignment as that of an object of type int. As a result, the two pointers reference equally aligned pointer types:

...

SEI CERT C++ Coding StandardVOID EXP56-CPP. Do not cast pointers into more strictly aligned pointer types
ISO/IEC TR 24772:2013Pointer Casting and Pointer Type Changes [HFC]
ISO/IEC TS 17961Converting pointer values to more strictly aligned pointer types [alignconv]
MISRA C:2012Rule 11.1 (required)
Rule 11.2 (required)
Rule 11.5 (advisory)
Rule 11.7 (required)

...