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)
"Could it be to stop the compiler from complaining about unused variables?"
yes
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.
If you set -Werror
option, the compiler makes all warnings into errors, stopping compilation. It's a good practice set -Wall -Werror
to check all inconsistences.
Yes, it's exactly to tell the compiler not to complain about unused variables.