main() 是否还有其他参数可以接受? [英] Are there any other arguments that main() can accept?
问题描述
我最近在搜索 C 中的环境变量时遇到了以下问题:
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.
main()
可以接受的所有可用参数是什么?
What are all of the available arguments that main()
can accept?
推荐答案
C99 和 C11 草案标准允许为 main
实现定义的参数集,这些参数将特定于这些系统(非便携).来自 5.1.2.2.1
部分:
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[...]
我能找到的唯一附加参数是 envp
和 apple
,我们可以在 维基百科关于入口点的 C 和 C++ 部分:
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:
C 和 C++ 还允许其他平台相关的格式标准,除了在 C++ 中,返回类型必须始终为 int;[6]例如,Unix(虽然不是 POSIX.1)和 Microsoft Windows 有一个第三个参数给出程序的环境,否则可以访问通过 stdlib.h 中的 getenv:
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 和 Darwin 的第四个参数包含任意操作系统提供的信息,例如执行二进制文件的路径:[7]
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);
看起来 Windows 有一个 Microsoft 特定的 wmain,它需要 <代码>wchar_t:
It looks like Windows has a Microsoft specific wmain which takes wchar_t
:
int wmain(int argc, wchar_t *argv[], wchar_t *envp[]);
这篇关于main() 是否还有其他参数可以接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!