在什么地方存储操作系统的命令行参数? [英] Where does the OS store the command line arguments?

查看:191
本文介绍了在什么地方存储操作系统的命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在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 you malloc/calloc (and possibly realloc later on). Trying to free 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屋!

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