自定义 C 命令行处理Customizing C Command-Line Processing

如果程序不采用命令行自变量,则可以通过取消使用执行命令行处理的库例程来节省少量空间。If your program does not take command-line arguments, you can save a small amount of space by suppressing use of the library routine that performs command-line processing. 此例程称为 _setargv(在宽字符环境中,称为 _wsetargv),如展开通配符参数中所述。This routine is called _setargv (or _wsetargv in the wide-character environment), as described in Expanding Wildcard Arguments. 若要禁止使用它,请在包含 main 函数的文件中定义一个不执行任何操作的例程,并将其命名为 _setargv(在宽字符环境中为 _wsetargv)。To suppress its use, define a routine that does nothing in the file containing the main function and name it _setargv (or _wsetargv in the wide-character environment). 随后,对 _setargv 或 _wsetargv 的调用由 _setargv 或 _wsetargv 的定义实现,并且不会加载库版本。The call to _setargv or _wsetargv is then satisfied by your definition of _setargv or _wsetargv , and the library version is not loaded.

同样,如果从不通过 envp 自变量访问环境表,则可以提供用来代替 _setenvp(或 _wsetenvp)的你自己的空例程(环境处理例程)。Similarly, if you never access the environment table through the envp argument, you can provide your own empty routine to be used in place of _setenvp (or _wsetenvp), the environment-processing routine.

如果程序在 C 运行库中调用 _spawn 或 _exec 系列例程,则不应停止环境处理例程,因为需使用此例程将环境从生成进程传递到新进程。If your program makes calls to the _spawn or _exec family of routines in the C run-time library, you should not suppress the environment-processing routine, since this routine is used to pass an environment from the spawning process to the new process.

另请参阅See Also

main 函数和程序执行main Function and Program Execution