是否有任何 Pascal 方言允许可变数量的参数? [英] Does any dialect of Pascal allow a variable number of arguments?

查看:52
本文介绍了是否有任何 Pascal 方言允许可变数量的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是年长程序员的问题.

多年前,我遇到了一种 Pascal 方言,它通过某种扩展允许可变数量的参数.

Years ago, I encountered a dialect of Pascal which allowed a variable number of arguments, through some kind of extension.

有谁知道当前的 Pascal 方言允许可变数量的参数?

Does anyone know of a current dialect of Pascal which allows a variable number of arguments?

鉴于 Pascal 不像以前那么受欢迎,如果答案是否定的,我不会感到惊讶.

Given that Pascal is not as popular as it used to be, I wouldn't be surprised if the answer is no.

顺便说一句,它更正确,不是说参数的可变数量,而不是参数吗?

BTW, it is more correct, isn't it, to say variable number of arguments, rather than parameters ?

推荐答案

没有.答案基于我使用过的帕斯卡方言;其他人可能会有所不同.

No. The answer is based on the Pascal dialects that I have used; others may be different.

原因是 Pascal 将参数按顺序压入堆栈帧,因此所有参数都通过距堆栈指针的固定偏移量来访问.相比之下,C 以相反的顺序推送参数,因此定义的参数处于固定偏移量,您可以通过指针算法访问额外"参数.我会尝试一些 ASCII 艺术:

The reason is that Pascal pushes arguments onto the stack frame in order, so all arguments are accessed via a fixed offset from the stack pointer. C, by comparison, pushes arguments in reverse order, so defined parameters are at fixed offset, and you can access "extra" arguments via pointer arithmetic. I'll try some ASCII art:

        Pascal                  C

                                ---------------------
                                |     extra arg     |
        ---------------------   ---------------------
        |     1st param     |   |     3rd param     |
        ---------------------   ---------------------
        |     2nd param     |   |     2nd param     |
        ---------------------   ---------------------
SP ->   |     3rd param     |   |     1st param     |
        ---------------------   ---------------------

至于参数与参数:据我所知,函数(方法)定义其参数,调用者传递参数.我相信,这个定义来自 Fortran 手册,因此您应该可以了解我的年龄:-)

As for parameter versus argument: as I learned it, the function (method) defines its parameters, the caller passes arguments. That definition came, I believe, from a Fortran manual, so that should give you an idea of how old I am :-)

这篇关于是否有任何 Pascal 方言允许可变数量的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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