Rule 19.1 and assigment between members of a struct

Moderators: misra-c, david ward

Post Reply
GerlindeKettl
Posts: 9
Joined: Thu Apr 15, 2010 8:01 am
Company: Continental AG

Rule 19.1 and assigment between members of a struct

Post by GerlindeKettl » Fri Nov 20, 2015 10:34 am

Does this code violate rule 19.1?

Code: Select all

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.

misra-c
Posts: 556
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 19.1 and assigment between members of a struct

Post by misra-c » Fri Dec 11, 2015 1:12 pm

Your code is compliant with rule 19.1, though will violate rule 19.2.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.19 Overlapping storage”