在什么地方存储操作系统的命令行参数? [英] Where does the OS store the command line arguments?
问题描述
我的工作在Linux上。在内存部分是存储的命令行参数(堆栈或堆)?
我试图执行免费(argv的)
,我得到一个分段错误。这是为什么?
我试图执行免费(argv的),我得到一个分段错误。这是为什么?
块引用>您只能
免费
你的malloc
/释放calloc
(也可能是的realloc
以后)。试图免费
别的调用未定义行为。一个(好)的方式UB表现是产生分段错误;一个(坏)的方式是使程序出现预期的工作。至于他们在哪里...读的 C99标准 - 。它的未指定
的串指向的argv数组应
能够MODI网络的计划,并保留节目之间的最后存储的值
启动和终止程序。
块引用>I am working on Linux. In which section of memory are the command line arguments stored (stack or heap)?
I tried to execute
free(argv)
and I got a segmentation fault. Why is that?解决方案I tried to execute free(argv) and I got a segmentation fault. Why is that?
You can only
free
what youmalloc
/calloc
(and possiblyrealloc
later on). Trying tofree
something else invokes Undefined Behaviour. One (good) way UB manifests itself is by producing a segmentation fault; a (bad) way is to make the program appear to work as intended.As to where they are ... read section 5.1.2.2.1 of the C99 Standard -- its unspecified.
the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.
这篇关于在什么地方存储操作系统的命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!