Menu

"Assigned a value that is never used" false positive because of union

Alan
2019-07-19
2019-07-22
  • Alan

    Alan - 2019-07-19

    Cppcheck will throw this style error on this section of code

    "Variable 'u.i' is assigned a value that is never used."

    I think this is a false positive, because u.i does get used, just in the form of u.f in the following statement.

    int main (void)
    {
       union
       {
          uint32_t i;
          float f;
       } u;
    
       u.i = 0x41200000;
    
       int d = u.f + 5;
    
       printf("d = %d\n", d);
    
       return 0;
    }
    
     
  • Paul Fultz

    Paul Fultz - 2019-07-19

    This is related to this issue: https://trac.cppcheck.net/ticket/8909

     
  • Daniel Marjamäki

    I created a separate ticket for this: https://trac.cppcheck.net/ticket/9226

     

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.