Menu

Overlapping red/write of union is undefined behavior

vix
2022-04-22
2022-04-28
  • vix

    vix - 2022-04-22

    I have this struct/union, to have a bitwise access in C99 codebase (not C++)

    typedef union {
        struct {
            uint32_t a:1;
            uint32_t b:1;
            uint32_t c:1;
            uint32_t d:29;
        };
        uint32_t    u32;
    } MyStruct;
    
    MyStruct m;
    

    When I do

    m.a = m.b = m.c = 0;

    cppcheck gives "Overlapping red/write of union is undefined behavior".
    Not sure if this is a real problem or a false positive.

    Can someone give an advise?

     
  • CHR

    CHR - 2022-04-28

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11013

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.