Reputation: 313
I am aware that the main
function can take two arguments: int argc
and char* argv[]
. This is well documented. However the main
function can also take a third argument. Does anyone one know what this argument is?
Upvotes: 1
Views: 311
Reputation: 153899
There are only two forms of main
which are required to be
supported, and which are portable to all platforms. But an
implementation can add any additional forms it wants: int main(
double )
would be legal, for example (although I've never heard
of an implementation which uses it), as would int main( char
const* arg0... )
. In practice, "classical" Unix would support
int main( int argc, char** argv, char** environ )
; this is
not required by Posix, and presumably, there are some Unix
which don't support it. Outside of the Unix world, many early
C implementations tried to look like Unix, and so may also
support this (today more for reasons of backwards compatibility
than to look like Unix).
It's not something you can count on, however.
Upvotes: 2
Reputation: 1047
The function main
may have also a forth argument on Mac OS, of the form char **apple
, "containing arbitrary OS-supplied information". See http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B for details.
Upvotes: 3
Reputation: 13207
You can pass char *env[]
, it need not be named like this, though, in order to pass a different set of environment-variables. You can change the environment the particular process is executing in.
See this article, there is an explanation.
Upvotes: 0
Reputation: 409136
It's the environment variables, and have the same type as the normal argv
. It's not part of the C++ standard though, but may still work on some systems.
It's from older UNIX systems, where the environment variables often was passed like this.
Upvotes: 3