void cast of argc and argv

前端 未结 4 1142
甜味超标
甜味超标 2021-02-07 13:19

I\'m looking at a piece of C++ code, and the first line in the main function caught my attention:

int main(int argc, const char* argv[]) {
    (void)argc; (void)         


        
4条回答
  •  野性不改
    2021-02-07 13:46

    Yes, it is to prevent the compiler from complaining about unused variables. In this case a better way would be:

    int main(int, char**) {
        ...
    }
    

    Leaving the parameters unnamed tells the compiler that they're there but are not used.

提交回复
热议问题