What happens when you don't follow the practice of argv and argc

Possible Duplicates:
main(int argc, char *argv[])
Main's Signature in C++

If i write:

int main(int argc, char** argv)

i get proper commandline input. What would happen if i wrote say,

int main(int foo, double fooDouble, fooType FooVar)

Is this OS-dependent or does it depend on the compiler?


Given that it does compile, it will still only be called with the argc and argv arguments.

So your fooDouble will get the pointer value of argv, and FooVar will get whatever value is in that register/stack space used for that argument position (which may not have been initialized by the callee, so it may hold any undefined value).


This code doesn't even have to compile. If it does, undefined behaviour may occur.


The effect of adding a third (or fourth, or fifth...) argument to main indeed depends on the operating system. For instance, on Windows (and I believe on Unix as well) you can have a third argument which grants access to the environment variables:

int main( int argc, char **argv, char **env )
链接地址: http://www.djcxy.com/p/72130.html

上一篇: tmain(int argc,

下一篇: 当你不遵循argv和argc的做法会发生什么