MISRA Discussion Forums
Rule 19.1 and assigment between members of a struct - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.19 Overlapping storage (https://forum.misra.org.uk/forumdisplay.php?fid=174)
+---- Thread: Rule 19.1 and assigment between members of a struct (/showthread.php?tid=1216)



Rule 19.1 and assigment between members of a struct - GerlindeKettl - 20-11-2015

Does this code violate rule 19.1?

Code:
struct s_tag {  
uint8 ReadPos;
uint8 WritePos; };
typedef struct s_tag s;

union u_tag {
s      Elements;
uint32 Value; };
typedef union u_tag u;

u NewState;
NewState.Elements.ReadPos  = NewState.Elements.WritePos;
My static code checker thinks it is a violation, but from my point of view I'm just assigning one member of a struct to a different member of the struct and they don't overlap in memory. That this struct is a member of a union should not matter as there is no assignment across the members of the union.


Re: Rule 19.1 and assigment between members of a struct - misra-c - 11-12-2015

Your code is compliant with rule 19.1, though will violate rule 19.2.