Menu

[constParameter] and main()

2023-07-10
2023-07-10
  • Martin Poupě

    Martin Poupě - 2023-07-10

    Hello,
    for following program:

    #include <stdio.h>
    int main(int argc,char *argv[])
    {
        printf("%s\n",argv[0]);
        return 0;
    }
    

    Cppcheck 2.11 says:

    tmp.c:3:25: style: Parameter 'argv' can be declared as const array [constParameter]
    int main(int argc,char *argv[])
    ^

    This is a tiny issue, but I think Cppcheck might exclude standardised fucntions (like main()) from constParameter check automatically.
    Best Regards Martin

     
  • CHR

    CHR - 2023-07-10

    Since argv is only read from, it can be declared as const. This is accepted in C and C++.

     
  • Martin Poupě

    Martin Poupě - 2023-07-10

    You are right, const argv pointer works on both Linux and Windows. However this change makes definition of main different than declaration (which is implicit).
    Lets hope it is harmless :-)
    Martin

     

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.