Menu

Reading struct

Anonymous
2016-04-21
2016-05-05
  • Anonymous

    Anonymous - 2016-04-21

    Hello,

    we have a struct, which we are using to read a header of a file.

    So it looks like:

    struct StructMyHeader {
        char            id[4];
        unsigned long   size;
        ...
    }
    
    struct MyHandle : MyParentHandle
    {
        MyHandle() : MyParentHandle() {}
        ~MyHandle() {};
    
        QFile file;
        StructMyHeader myHeader;
    };
    
    bool readFile(...)
    {
        ...
        file.read(reinterpret_cast<char*>(&myHeader), sizeof(StructMyHeader));
        ...
    }
    

    But if we do so, we got some hundreds warnings of Cppcheck because of unusedStructMember (we don't handle all values of header) and an uninitMemberVar hint in MyHandle. Is there a clean way to supress this warnings just for this struct without adding a cppcheck supressing hint to each member? I think a simple memset is not enough?

    Regards
    SunBlack

     
  • Daniel Marjamäki

    One way is to put StructMyHeader in a header file. This check only warns for structs declared in the non-included source file.

    But it also feels like the check should somehow know that file.read will access all the struct members.

     

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.