https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123141

            Bug ID: 123141
           Summary: Warning flag -Wmain gives misleading argument count
                    suggestions for the main application function
           Product: gcc
           Version: 13.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petculescucodrut at yahoo dot com
  Target Milestone: ---

I've discovered that in all versions (or as far as I've tested) of the GNU
Compiler the "-Wmain" (and by extension "-Wall") parameter triggers an
incorrect message that contradicts the GNU C Language Intro & Reference, page
22.6[1], which specifies the main function may have no parameter, 2 parameters
or 3 parameters. These in their order are argc, argp and envp respectively.
However, when a app is incorrectly compiled with a number of parameters
different than 0, 2 or 3, the following warning is displayed

codrut@Codrut-Computer:~/Downloads$ gcc-13 app.c -Wall -o app
app.c:1:5: warning: ‘main’ takes only zero or two arguments [-Wmain]
    1 | int main(int argc, char *argv[], char *envp[], int test) {

The warning is generated in the correct situation, but the message itself does
not match the scenario for the enviroment in which It's generated. The message
should say "‘main’ takes only zero, two or three arguments", or at least
specify less vaguely what number of parameters (any maybe for what purpose) can
be included.

Here's a minimal code example which triggers this response in which I've added
4 parameters and the error was triggered:
file test.c:
int main(int argc, char *argv[], char *envp[], int test) {
}

And to compile:
codrut@Codrut-Computer:~/Downloads$ gcc-13 -Wmain test.c
test.c:1:5: warning: ‘main’ takes only zero or two arguments [-Wmain]
    1 | int main(int argc, char *argv[], char *envp[], int test) {
      |     ^~~~

References:
[1]
https://www.gnu.org/software/c-intro-and-ref/manual/html_node/The-main-Function.html
[+] http://crasseux.com/books/ctutorial/Environment-variables.html
[+] https://learn.microsoft.com/en-us/cpp/c-language/arguments-to-main

Reply via email to