The direct answer to your question is that the variables have to be declared somewhere for the compiler to find them. In dos.h
, or some file included in dos.h
, there is a definition for _argc
and _argv
.
If you didn't include dos.h
, you would still somewhere have to declare extern int _argc;
and extern char *_argv[];
to be able to use them. Otherwise you'll get a compiler error because the compiler won't have any idea what these variables are.
These variables are probably provided by your C runtime. When you build a program, your compiler and linker put in all sorts of supporting boilerplate code involved with starting your app. If you're wondering where these variables actually exist, it's in this boilerplate startup code.
(This startup code is what gets run when your program launches. The startup code then hands off control to your program by calling your main()
function.)
For this specific case, though, you really want to use the argc
and argv
provided to main()
as defined by the C standard. That would make your program portable to all C compilers and not limited to your specific (probably ancient) compiler. Quoth the standard,
The function called at program startup is named main . The
implementation declares no prototype for this function. It can be
defined with no parameters:
int main(void) { /*...*/ }
or with two parameters (referred to here as argc and argv , though any
names may be used, as they are local to the function in which they are
declared):
int main(int argc, char *argv[]) { /*...*/ }
And of course if you use these argc
and argv
, you certainly don't need dos.h
.