Menu

Behaviour with different compile options

2023-12-11
2023-12-14
  • Marius Urban

    Marius Urban - 2023-12-11

    I have a function with a pointer as a parameter. The pointer is read, but the only write happens in a function call exclusive to a #if Feature. Similar to this minimal snippet.
    `
    void fun(myStruct *pStruct, int other, int parameters) {
    ... more code here
    #if Feature
    //pStruct only changed in this function
    mutatesMyStruct(pStruct);
    #endif
    ... more code here
    }

    void mutatesMyStruct(myStruct *pStruct){...}
    `
    I then use cmake to generate compile commands for both feature flags and merge the resulting json files and use it as the --project.
    When I now generate a report with cppcheck I get the following style warning:
    Parameter pStruct can be declared as pointer to const"

    Is this the intended behaviour? And if yes is there a better way to do this or to circumvent this warning without supressing it?

     
  • Daniel Marjamäki

    It is not intended in my opinion.. I have created this ticket:
    https://trac.cppcheck.net/ticket/12265

     

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.