函数如何在内部工作 [英] How function works internally

查看:80
本文介绍了函数如何在内部工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道当c程序执行$ ​​b $ b时内部会发生什么。 LIke,

当我们调用一个函数时,所有以前的值将被推送到

堆栈并且该特定函数的局部变量将是

推入堆栈。当函数返回时,所有本地

变量都将被激活出来..


这样,当我们调用strcpy函数时会发生什么。在

堆栈中会发生什么?


我想知道从哪里可以得到这些信息。任何

网站..


i搜索了很多,但无法找到。


提前致谢


Deepthy

Hi,

I would like to know what happens internally when a c programme is
executed. LIke,
when we call a function, all the previous values will be pushed on to
stack and the local variables of that particular function will be
pushed in to the stack. when the function returns, all the local
variables will be poped out..

like this, what happens when we call a strcpy function. what happens in
stack??

i would like to know from where we can get this information. any
sites..

i searched alot, but couldnt find.

Thanks in advance

Deepthy

推荐答案



marydeep ... @ gmail.com写道:

marydeep...@gmail.com wrote:




我想知道当ac程序内部发生了什么

已执行。 LIke,

当我们调用一个函数时,所有以前的值将被推送到

堆栈并且该特定函数的局部变量将是

推入堆栈。当函数返回时,所有本地

变量都将被激活出来..


这样,当我们调用strcpy函数时会发生什么。在

堆栈中会发生什么?


我想知道从哪里可以得到这些信息。任何

网站..


i搜索了很多,但无法找到。


提前致谢


Deepthy
Hi,

I would like to know what happens internally when a c programme is
executed. LIke,
when we call a function, all the previous values will be pushed on to
stack and the local variables of that particular function will be
pushed in to the stack. when the function returns, all the local
variables will be poped out..

like this, what happens when we call a strcpy function. what happens in
stack??

i would like to know from where we can get this information. any
sites..

i searched alot, but couldnt find.

Thanks in advance

Deepthy



如果您真的想知道这一点,请参阅gcc生成的汇编代码

。 ;-p

If you really want to know this, please see the assembly code generated
by gcc. ;-p


ma **** *****@gmail.com 写道:
ma*********@gmail.com wrote:

这样,当我们调用strcpy函数时会发生什么。在

堆栈中会发生什么?


我想知道从哪里可以得到这些信息。任何

网站..
like this, what happens when we call a strcpy function. what happens in
stack??

i would like to know from where we can get this information. any
sites..



函数调用的具体细节由

实现定义,而不是标准。


在某些实现中很容易检查过程调用。


例如,如果你使用GCC,只需给出它是-S开关并查看

asm输出。


或者如果你真的想深入研究,你可以学习GCC
文档(例如), http://gcc.gnu.org/ onlinedocs /

或GCC内部(单独的手册)。


如果由于某种原因你不使用GCC,你会必须去其他地方

文档。

The specific details of the function call are defined by the
implementation, not the standard.

It is very easy to inspect the procedure call in some implementations.

For example, if you use GCC, just give it the -S switch and look at the
asm output.

Or if you really want to go in depth, you can study the GCC
documentation (for example), http://gcc.gnu.org/onlinedocs/
or the GCC internals (a separate manual).

If you don''t use GCC for some reason, you will have to go elsewhere for
documentation.


ma ********* @ gmail.com 写道:

我想知道ac程序内部会发生什么是

执行特德。 LIke,当我们调用一个函数时,所有先前的值

将被推送到堆栈,并且该特定函数的局部变量将被推入堆栈。当

函数返回时,所有局部变量都将被激活..


这样,当我们调用strcpy函数时会发生什么。在

堆栈中会发生什么?
I would like to know what happens internally when a c programme is
executed. LIke, when we call a function, all the previous values
will be pushed on to stack and the local variables of that
particular function will be pushed in to the stack. when the
function returns, all the local variables will be poped out..

like this, what happens when we call a strcpy function. what happens in
stack??



这不是由语言定义的,不同的编译器可以和

以不同方式处理。


并非每个实现都有一个堆栈,就某个特定方向增长的连续内存区域而言。还有

实现相当于堆分配

为函数调用分配内存。


有de某些系统的事实标准。我认为你要找的是一个ABI(应用程序二进制接口,我认为)。

搜索它可能会给你一些信息 - 但保留介意

您发现的任何内容都是系统特定的。


如果您想知道语言实际需要什么,您可以获得

通过搜索n1124.pdf获得ISO C标准的最新草案。

(绝对不是轻读。)


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http: //www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

This is not defined by the language, and different compilers can and
do handle this differently.

Not every implementation has a "stack", in the sense of a contiguous
region of memory that grows in a particular direction. There are
implementations that do the equivalent of a heap allocation to
allocate memory for a function call.

There are de facto standards for some systems. I think what you''re
looking for is an ABI (Application Binary Interface, I think).
Searching for that might give you some information -- but keep in mind
that anything you find will be system-specific.

If you want to know what the language actually requires, you can get
the latest draft of the ISO C standard by search for "n1124.pdf".
(It''s definitely not light reading.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于函数如何在内部工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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