çargv的是什么数据的最大大小 [英] C argv what is the maximum size of data

查看:111
本文介绍了çargv的是什么数据的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/7498892/about-command-line-arguments-of-main-function\">About主要功能的命令行参数

我将如何确定哪些数据的最大尺寸,我可以传递到一个C主(INT ARGC,字符* argv的)?是否有标准的宏的地方,将定义这个?是拥有的主进程的数据(即我的程序存储这些数据),或者是莫名其妙地拥有操作系统和我只能得到一个指向它?

How would I determine what the maximum size of data I could pass into a C main(int argc, char* argv)? Is there a macro somewhere in the standard that would define this? Is the data "owned" by the main process (i.e. does my program store this data) or is it somehow "owned" by the operating system and I can just get a pointer to it?

推荐答案

在一个POSIX系统中,有一个值, ARG_MAX 中的 &LT;&limits.h中GT; _POSIX_ARG_MAX (这是4096)的最小允许值。您可以通过 的sysconf发现在运行时的数值( ) SC_ARG_MAX 参数的功能。

In a POSIX system, there is a value, ARG_MAX, defined in <limits.h> with a minimum acceptable value of _POSIX_ARG_MAX (which is 4096). You can discover the value at run-time via the sysconf() function with the SC_ARG_MAX parameter.

它往往是256昆明植物研究所。

It is often 256 KiB.

的argv 数据(指针都阵列和它们指向的字符串)都拥有的程序。它们可以被修改;这是否是明智的取决于你的观点。你当然不能什么传递给的main()功能范围之外的步骤,而不必调用未定义的行为。比如GNU功能 getopt的()时,没有在环境中设置了POSIXLY_CORRECT环境变量运行不重组的论点。你已经有一个指针数据的argv 作为提供给的main()

The data in argv (both the array of pointers and the strings that they point at) are 'owned' by the program. They can be modified; whether that is sensible depends on your viewpoint. You certainly can't step outside the bounds of what was passed to the main() function without invoking undefined behaviour. Functions such as GNU getopt() do reorganize the arguments when run without the POSIXLY_CORRECT environment variable set in the environment. You already have a pointer to the data in the argv as provided to main().

根据经验,你会经常发现数据字符串的argv结束后立即[ARGC-1] 实际上是对环境的开始。主程序可以写成 INT主(INT ARGC,字符** argv的,字符** envp)在某些系统(公认的C标准附件J在扩展,§J.5.1),其中 envp 是存储在全局变量 ENVIRON ,并且是相同的值指针的空值终止阵列环境字符串的开始。

Empirically, you will often find that the data immediately after the end of the string argv[argc-1] is actually the start of the environment. The main program can be written as int main(int argc, char **argv, char **envp) in some systems (recognized as an extension in the C standard Annex J, §J.5.1), where envp is the same value as is stored in the global variable environ, and is the start of a null-terminated array of pointers to the environment strings.

这篇关于çargv的是什么数据的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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