[fpc-pascal] Variable arguments, different types?

L505 fpc505 at z505.com
Thu Mar 9 17:23:42 CET 2006



>
> > I have also read people stating things like this before:
> >
> > "you can use array of const but you can't make functions like writeln
> > because writeln accepts multiple types".
>
> Usually the statement is about different _numbers_ of arguments, not
> different types. Writing subroutine which accept different types for
> their arguments has never been a problem in Pascal.

I was talking specifically about array of const, not Pascal in general. The docs
do not make it clear that array of const can accept different types in "one
call". We are talking purely about "array of const" here, not the Pascal
language in general. Of course I know the Pascal language can accept multiple
types in one call.

>
> > But in fact, with array of const, you can use multiple types.
>
> You can, just as you can use different types in record types.
> Still, the  actual argument type would be the type of the record or, as in
> your case "array of const" then. Don't confuse that.

Well you are nitpicking my email :-). I'm not confused at all - the docs are.
All I was asking was why specifically in array of const's case, the docs did not
make it clear I could pass multiple types in the same call. If you look in the
examples in the docs page, all the examples show the programmer passing
arguments of the same type in one call.

They only make it clear that you can pass multiple types in separate calls, not
in the same call.

// passing multiple types, but in separate calls
test([TRUE, FALSE, TRUE]);
test(['string1', 'string2', 'string3']);

// passing MULTIPLE TYPES IN ONE CALL, not stated anywhere in docs
test([TRUE, 'string1', 342, -456, 1.653]);


>
> And you still can't just pass two arguments when the subroutine expects
> only one

Isn't this exactly what array of const is for? It allows you to use anywhere
from 1 to unlimited parameters.




More information about the fpc-pascal mailing list