在C中调用函数 [英] calling functions in C

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

问题描述

有人可以解释一下,在打电话给

功能时会发生什么。具体来说,我想知道堆栈中发生了什么。


当函数

时,为什么只传递2个参数或5个参数原型需要3.


谢谢。

Hi, Can someone please explain me what''s going on during a call to a
function. Specifically, I wanted to know what''s going on in Stacks.

Why is it ok to pass only 2 parameters or 5 parameters when the function
prototype requires 3.

thanks.

推荐答案

袁忠写于26/07 / 04:
Yuan Zhong wrote on 26/07/04 :
有人可以解释一下在调用
函数期间发生了什么。


执行程序绕过一个子程序,并在

结束时恢复该函数或返回。参数的值可以从函数中更改为
。可以取消引用类型指针参数。

可以返回一个值。

具体来说,我想知道Stacks中发生了什么。


这取决于实施。有些没有堆栈。

当函数
原型需要3时,为什么只传递2个参数或5个参数。
Can someone please explain me what''s going on during a call to a
function.
The execution is detoured to a subroutine and resumed once the end of
the function or ''return'' is reached. The values of the parameters are
redable from the fuction. Typed pointer parameters can be dereferenced.
A value can be returned.
Specifically, I wanted to know what''s going on in Stacks.
It depends on the implementation. Some have no stack.
Why is it ok to pass only 2 parameters or 5 parameters when the function
prototype requires 3.




这是一个未定义的行为。结果可以是任何东西。


-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq。 HTML


C是一个尖锐的工具



It''s an undefined behaviour. The result can be anything at all.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"


2004年7月26日星期一袁忠写道:
On Mon, 26 Jul 2004, Yuan Zhong wrote:
有人可以解释一下在调用
函数时发生的事情。具体来说,我想知道Stacks中发生了什么。


对于C语言,没有一个答案。每个人创建C编译器的方式都很灵活。您可以问一下如何在编译器上实现

。对于这个问题,你需要找到一个新闻组,

处理你的特定编译器。例如,gcc编译器有新闻组,你可以问这个。

当函数
原型需要3。
Hi, Can someone please explain me what''s going on during a call to a
function. Specifically, I wanted to know what''s going on in Stacks.
There is no one answer to this for C language. There is flexibility in how
each person creates their C compiler. You could ask how is it implemented
on your compiler. For that question you''ll need to find a newsgroup that
deals with your specific compiler. For example, there are newsgroups for
the gcc compiler where you could ask this.
Why is it ok to pass only 2 parameters or 5 parameters when the function
prototype requires 3.




否。如果你这样做,任何好的编译器都不会编译代码。唯一的

例外是函数原型有...的时候。例如,

printf原型是:


int printf(const char *,...);


这意味着它可以采用一个或多个输入参数。多少输入

参数取决于第一个参数的格式。例如,如果

,则第一个参数是%d%d%d。然后它将需要三个输入(每个%d一个

)。


-

发送电子邮件至:darrell at cs dot toronto dot edu

不要发电子邮件给 vi ************ @ whitehouse.gov


袁忠写道:
你好,有人可以解释一下在调用
函数期间发生了什么。具体来说,我想知道堆栈中发生了什么。

在某些编译器中,参数被推送。在堆栈上。其他

实现通过寄存器传递参数。

返回时,一些实现将返回值放在

堆栈上。从堆栈中弹出参数可能是调用协议或函数协议的责任。


某些实现可以传递返回值通过寄存器。


当函数
原型需要3时,为什么只传递2个参数或5个参数。

谢谢。
Hi, Can someone please explain me what''s going on during a call to a
function. Specifically, I wanted to know what''s going on in Stacks.
In some compilers, the parameters are "pushed" onto a stack. Other
implementations pass parameters via registers.

Upon a return, some implementations place the return value on the
stack. The popping of arguments off of the stack may be the
responsibility of the calling protocol or the function''s protocol.

Some implementations can pass return values via registers.

Why is it ok to pass only 2 parameters or 5 parameters when the function
prototype requires 3.

thanks.



显示代码。


在C ++中,可以为参数分配默认值。因此,如果调用者未提供

参数,则函数接收默认值

。但是,这是另一个新闻组的问题。

-

托马斯马修斯


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http:/ /www.parashift.com/c++-faq-lite

C常见问题: http://www.eskimo.com/~scs/c-faq/top.html

alt.comp。 lang.learn.c-c ++ faq:
http ://www.raos.demon.uk/acllc-c++/faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍


Show the code.

In C++, parameters can be assigned default values. So that if the
parameter is not supplied by the caller, the function receives
the default value. But, that is an issue for another newsgroup.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


这篇关于在C中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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