1. <i id='eUI52'><tr id='eUI52'><dt id='eUI52'><q id='eUI52'><span id='eUI52'><b id='eUI52'><form id='eUI52'><ins id='eUI52'></ins><ul id='eUI52'></ul><sub id='eUI52'></sub></form><legend id='eUI52'></legend><bdo id='eUI52'><pre id='eUI52'><center id='eUI52'></center></pre></bdo></b><th id='eUI52'></th></span></q></dt></tr></i><div id='eUI52'><tfoot id='eUI52'></tfoot><dl id='eUI52'><fieldset id='eUI52'></fieldset></dl></div>

      <small id='eUI52'></small><noframes id='eUI52'>

    2. <tfoot id='eUI52'></tfoot>
      <legend id='eUI52'><style id='eUI52'><dir id='eUI52'><q id='eUI52'></q></dir></style></legend>

        <bdo id='eUI52'></bdo><ul id='eUI52'></ul>

      C/C++ 主函数的参数在哪里?

      时间:2023-09-27

      <i id='5ucjC'><tr id='5ucjC'><dt id='5ucjC'><q id='5ucjC'><span id='5ucjC'><b id='5ucjC'><form id='5ucjC'><ins id='5ucjC'></ins><ul id='5ucjC'></ul><sub id='5ucjC'></sub></form><legend id='5ucjC'></legend><bdo id='5ucjC'><pre id='5ucjC'><center id='5ucjC'></center></pre></bdo></b><th id='5ucjC'></th></span></q></dt></tr></i><div id='5ucjC'><tfoot id='5ucjC'></tfoot><dl id='5ucjC'><fieldset id='5ucjC'></fieldset></dl></div>

          • <small id='5ucjC'></small><noframes id='5ucjC'>

              <tbody id='5ucjC'></tbody>
          • <tfoot id='5ucjC'></tfoot>
          • <legend id='5ucjC'><style id='5ucjC'><dir id='5ucjC'><q id='5ucjC'></q></dir></style></legend>

                <bdo id='5ucjC'></bdo><ul id='5ucjC'></ul>
                本文介绍了C/C++ 主函数的参数在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在C/C++中,main函数接收char*类型的参数.

                In C/C++, the main function receives parameters which are of type char*.

                int main(int argc, char* argv[]){
                  return 0;
                }
                

                argv 是一个 char* 数组,指向字符串.这些字符串位于何处?它们是在堆、栈还是其他地方?

                argv is an array of char*, and points to strings. Where are these string located? Are they on the heap, stack, or somewhere else?

                推荐答案

                其实就是编译器依赖和操作系统依赖的结合.main() 和其他任何 C 函数一样是一个函数,所以 argcargv 两个参数的位置将遵循编译器的标准平台上.例如对于大多数面向 x86 的 C 编译器,它们将位于返回地址和保存的基指针上方的堆栈上(记住,堆栈向下增长).在 x86_64 上,参数在寄存器中传递,因此 argc 将在 %edi 中,argv 将在 %rsi 中.编译器生成的 main 函数中的代码然后将它们复制到堆栈中,这就是后面的引用指向的地方.这样寄存器就可以用于来自 main 的函数调用.

                It's actually a combination of compiler dependence and operating system dependence. main() is a function just like any other C function, so the location of the two parameters argc and argv will follow standard for the compiler on the platform. e.g. for most C compilers targeting x86 they will be on the stack just above the return address and the saved base pointer (the stack grows downwards, remember). On x86_64 parameters are passed in registers, so argc will be in %edi and argv will be in %rsi. Code in the main function generated by the compiler then copies them to the stack, and that is where later references point. This is so the registers can be used for function calls from main.

                argv 指向的 char* 块和实际的字符序列可以在任何地方.它们将从某个操作系统定义的位置开始,并且可能会被链接器生成的前导码复制到堆栈或其他地方.您必须查看 exec() 的代码和链接器生成的汇编程序前导码才能找出答案.

                The block of char*s that argv points to and the actual sequences of characters could be anywhere. They will start in some operating system defined location and may be copied by the pre-amble code that the linker generates to the stack or somewhere else. You'll have to look at the code for exec() and the assembler pre-amble generated by the linker to find out.

                这篇关于C/C++ 主函数的参数在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:常量引用和普通参数的区别 下一篇:我们什么时候需要将数组的大小作为参数传递

                相关文章

                1. <i id='uC2xW'><tr id='uC2xW'><dt id='uC2xW'><q id='uC2xW'><span id='uC2xW'><b id='uC2xW'><form id='uC2xW'><ins id='uC2xW'></ins><ul id='uC2xW'></ul><sub id='uC2xW'></sub></form><legend id='uC2xW'></legend><bdo id='uC2xW'><pre id='uC2xW'><center id='uC2xW'></center></pre></bdo></b><th id='uC2xW'></th></span></q></dt></tr></i><div id='uC2xW'><tfoot id='uC2xW'></tfoot><dl id='uC2xW'><fieldset id='uC2xW'></fieldset></dl></div>
                  <legend id='uC2xW'><style id='uC2xW'><dir id='uC2xW'><q id='uC2xW'></q></dir></style></legend>

                    <tfoot id='uC2xW'></tfoot>

                    <small id='uC2xW'></small><noframes id='uC2xW'>

                      <bdo id='uC2xW'></bdo><ul id='uC2xW'></ul>