函数和过程的参数传递顺序问题。(100分)

  • 主题发起人 主题发起人 fuyaping
  • 开始时间 开始时间
F

fuyaping

Unregistered / Unconfirmed
GUEST, unregistred user!
以下两个题目说法上有没有什么问题?
如果没有问题的话,这两个题目的答案分别是什么?

1、关于多个参数的函数调用,下列错误的说明是?( )
A.参数传递按从右到左从左到右的顺序
B.参数传递按从左到右的的顺序
C.参数传递无顺序
D.参数传递可自行任意规定

2、关于多个参数的过程调用,下列错误的说明是?( )
A.参数传递按从左到右的顺序
B.参数传递按从右到左的顺序
C.参数传递无顺序
D.参数传递可自行任意规定


 
????
这两题是不是一样的啊?
一般而言,pascal调用函数,参数是从左到右传递,即时参数列表中
左边的参数先进入堆栈。
C语言是从右到左入栈。
 
up~~~
不是一个题目啊,看清楚了,这是一张破试卷上的题目,我觉得有问题!
 
哪个高人帮帮忙啊?
 
从左到右,一个一个对上不就可以了吗?干吗搞得哪么复杂。
 
自己UP~~~~~~~~~~
 
函数与过程的调用顺序在同一种语言中是一样的。
只不过多了一个返回值!
 
函数和过程的调用中参数的顺序必须按其定义的顺序进行,你自己选择吧!
 
我也是一个初学者,这在学习object pascal(一般都是一本书的第二章)
正好看到了,函数和过程的参数调用的顺序问题
在函数和过程的定义中
fonction miao008(miao:name,miao008:name):name;pascal;(左向右读)
fonction miao008(miao:name,miao008:name):name;stdcall:(right->left)
一般而言默认的情况下是从左向右读
所以选d
 
还有什么好说的,第一位朋友就已经回答了你的问题了
默认情况下就是从左到右,不管是函数还是过程。
加上 stdcall 就是从右到左,不管是函数还是过程。
 
参数传递是由函数声明的规则决定的:Stdcall,pascal,cdecl等等。
所以不能一概而论。
你可以先看看 procedure 和 function 声明的帮助文档
 
呵呵,我还没有留意过这个问题,不过具体来说,没有多大的意义吧。
 
愚见
if 单选 then 答案=C
else 答案=ABC
 
高见!
完全同意beyondair的回答!
 
查阅Object Pascal帮助 Calling conventions.
When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example,
function MyFunction(X, Y: Real): Real
cdecl;
...
Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.
The register and pascal conventions pass parameters from left to right
that is, the left most parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.
The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
The safecall convention implements exception "firewalls." On Windows, this implements interprocess COM error notification.
The table below summarizes calling conventions.
Calling conventions
Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No
The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)

The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.
 
完全同意beyondair的回答!
 
1、参数传递顺序
Register, pascal的传递顺序是从左到右的,也就是说,左边的参数先被计算和求值;而cdecl, stdcall, safecall则刚好相反。
 
yoking兄不是写的很清楚了吗
 
The register and pascal conventions pass parameters from left to right;
 
后退
顶部