MISRA C:2025 Rule 19.3
R2026bDescription
A union member shall not be read unless it has been previously set.1
Rationale
In C, all members of a union share the same region of memory. When you write to one member and then read a different member, the stored bit pattern is reinterpreted as a different type. The C standard defines this reinterpretation as undefined behavior or implementation-defined behavior, depending on the types involved. The resulting value is unpredictable and can change between compilers, optimization levels, or target platforms.
Polyspace Implementation
Polyspace® reports a violation of this rule when:
A union member is read after a different member was explicitly assigned in the same function.
The checker can determine that the active member (most recently written) differs from the member being read.
No violation is reported when the active member is unknown. The active member is unknown in these situations:
The union is passed as a function parameter with no assignment visible in the current scope.
Divergent
if/elsebranches assign different union members.A union member is written through a pointer alias.
The checker operates at function level and does not track union member activity across function calls.
As an exception, reading a character array member such as uint8_t[] is
not flagged. MISRA C:2025 allows byte-level access to union storage through character
arrays.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Overlapping storage |
| Category: Required |
| AGC Category: Required |
PQL Name: std.misra_c_2025.R19_3 |
Version History
Introduced in R2026b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C:2025
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.