Search code examples
language-featurespascal

Does any dialect of Pascal allow a variable number of arguments?


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 ?


Solution

  • 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:

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

    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 :-)