main()可以接受其他参数吗? [英] Are there any other arguments that main() can accept?

查看:106
本文介绍了main()可以接受其他参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在搜索有关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定义的一组参数,这些参数将特定于那些系统( non -便携式).从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[...]

我能找到的仅有的其他参数是envpapple,我们可以在

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆