Scooter Scooter - 12 days ago 9
C Question

How do I get rid of the unused parameter warning in C with gcc 4.8.4 [-Wunused-parameter]

Using gcc 4.8.4 -Wall -Wextra -Wpedantic. I want to use argv for the executable name and have no need for argc.

If I do

int main(int argc, char *argv[])


I get this warning:

abc.c:5:14: warning: unused parameter ‘argc’ [-Wunused-parameter]


In the past I have just done

int main(int, char *argv[])


to get rid of the warning, but that may have been C++. Now I get an error:

abc.c:5:1: error: parameter name omitted


Is there a way to access argv and not get a warning for not accessing argc?

Answer

My comment was unclear: like this

int main(int argc, char *argv[])
{
    char *prog = argv[0];
    (void)argc;
    return 0;
}