📄 6.5.0.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<body>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.4.4.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.5.1.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>6.5 参数传递</b></font>
<table><tr><td>    </td>
<td class="content">
<P>
当一个过程调用另一个过程时,在它们之间进行通信的常用方法是通过非局部名字和被调用过程的参数来实现的。图6.22中的过程使用非局部名字和参数二者来交换a[i]与a[j]的值。这里的数组a非局部于过程exchange,i和j是它的形式参数。
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
(1) <b><font color="#0000FF">procedure</font></b> exchange(i,j:integer); <br>
(2) <b><font color="#0000FF">var</font></b> x: integer; <br>
(3) <b><font color="#0000FF">begin</font></b> <br>
(4) x:=a[i];a[i]:=a[j];a[j]:=x <br>
(5) <b><font color="#0000FF">end</font></b> </p>
<p> <b>图6.22</b> 带有非局部量和参数的Pascal过程exchange
<p>
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
在这一节中将讨论几种把实在参数和形式参数联系起来的常用方法。它们是:传值调用(call-by-value),引用调用(call-by-reference),复制恢复(copy-restore),传名调用(call-by-name),和宏扩展(macro expansion)。知道一种语言(或编译器)使用哪种参数传递方法是很重要的,因为程序的结果可能依赖于所用的方法。
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
为什么有这么多种方法呢?不同的方法是根据如何解释表达式代表什么而产生的。如象下面这样的赋值语句:
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
a[i]:=a[j]
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
其中表达式a[j]代表一个值,而a[i]则表示一个存储地址,赋值的结果是将a[j]的值存放于地址为a[i]的单元中。究竟是使用一个表达式代表的存储地址还是它所代表的值,将分别由表达式出现在赋值符号的左边或右边来决定。出现在赋值符号左边的要用表达式的左-值,或说l-值(left-value),即表达式所表示的存储地址;出现在赋值符号右边的要用表达式的右-值,或r-值(right-value),即表达式所表示的值。参数传递方法之间的区别主要基于实在参数是代表右-值、左-值、或者实在参数的正文本身。因而也就出现了多种方法。
</p>
</td></tr></table>
<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.4.4.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.5.1.htm'"></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -