Pascal 的任何方言是否允许可变数量的参数?
这是老程序员的问题。
几年前,我遇到了 Pascal 的一种方言,它通过某种扩展允许可变数量的参数。
有谁知道当前的 Pascal 方言允许可变数量的参数?
鉴于 Pascal 不再像以前那样流行,如果答案是否定的,我不会感到惊讶。
顺便说一句,说可变数量的参数比参数更正确,不是吗?
This is a question for the older programmers.
Years ago, I encountered a dialect of Pascal which allowed a variable number of arguments, through some kind of extension.
Does anyone know of a current dialect of Pascal which allows a variable number of arguments?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不。答案是基于我使用过的 Pascal 方言;其他人可能会有所不同。
原因是 Pascal 按顺序将参数推送到堆栈帧上,因此所有参数都是通过距堆栈指针的固定偏移量来访问的。相比之下,C 以相反的顺序推送参数,因此定义的参数位于固定偏移处,并且您可以通过指针算术访问“额外”参数。我将尝试一些 ASCII 艺术:
至于参数与参数:据我了解,函数(方法)定义其参数,调用者传递参数。我相信这个定义来自 Fortran 手册,所以这应该能让你知道我的年龄:-)
No. The answer is based on the Pascal dialects that I have used; others may be different.
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:
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 :-)
您可以在delphi中使用可选参数来获得相同的效果:
或者重载方法:
或者您可以使用变量数组作为参数:
You can use optional arguments with delphi to get the same effect:
Or overloaded methods:
Or you can use a variable array for parameters:
GNU-Pascal(基于 gcc)afaik 将 1:1 映射到 C 支持。使用类似
Delphi/Free Pascal 语法的 function Something(arg:pchar;...) 具有“const 数组”支持,这是一个类型安全版本,以及用于 C 接口(D6 或 D7+)的 varargs 指令
GNU-Pascal (gcc based) afaik maps 1:1 to C support. using function something(arg:pchar;...) like syntax
Delphi/Free Pascal has "array of const" support, which is a typesafe version, and a varargs directive for the C interfacing (D6 or D7+)
您可能正在考虑一个可用于 Turbo Pascal 的库,其中他们有这样的 hack。我的语法对于对象及其下降有点生疏。
您可以根据需要链接任意数量的参数。最后一个必须以 nil 结束。
You are probably thinking of a library that was available for Turbo Pascal where they had a hack like this. My syntax is a bit a rusty for objects and descending from it.
You could just chain as many arguments as you wanted. The last one had to be terminated with nil.
是的!
使用
params
关键字:Yes!
Use the
params
keyword: