Search code examples
cargumentsprogram-entry-pointargvargc

Are there any other arguments that main() can accept?


I recently came across the following in my searches regarding environment variables in C:

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

I have searched around and can't find anything conclusive regarding my question.

What are all of the available arguments that main() can accept?


Solution

  • The C99 and C11 draft standards allow for implementation defined set of parameters to main, these parameters are going to be specific to those systems(non-portable). From section 5.1.2.2.1:

    [...]or in some other implementation-defined manner[...]

    The only additional parameters I can find documented are envp and apple, we can find a good description in Wikipedia's C and C++ section on Entry Points:

    Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must always be int;[6] for example, Unix (though not POSIX.1) and Microsoft Windows have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h:

    int main(int argc, char **argv, char **envp);
    

    Mac OS X and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:[7]

    int main(int argc, char **argv, char **envp, char **apple);
    

    It looks like Windows has a Microsoft specific wmain which takes wchar_t:

    int wmain(int argc, wchar_t *argv[], wchar_t *envp[]);