[fpc-pascal] bounded array types as procedure arguments
P Padilcdx
ppadilcdx at gmail.com
Sun Oct 24 17:30:44 CEST 2021
Thank you for the clear explanation.
> On Oct 24, 2021, at 1:05 AM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
>
>
> On Sat, 23 Oct 2021, P Padilcdx via fpc-pascal wrote:
>
>> Hello,
>>
>> Was trying to declare a procedure with an array argument, e.g. procedure
>> p(a: array[1..9] of int64), and the compiler complained as it seems only
>> accepts open arrays. If I set a type alias for the array, e.g. type t =
>> array[1..9] of int64, then I can declare the procedure p(a: t). This
>> behavior seems odd, why couldn’t I declare the procedure with a bounded
>> array without having to declare a type alias first?
>
> You can never declare a new type in a procedure header.
> For example you also cannot do
>
> procedure (a ; record x,y : integer; end);
> or
> procedure (a : (one,two,three));
>
> The reason is type compatibility: the argument type is unknown outside the procedure
> and therefor the compiler will never allow you to assign something to it,
> since there is no way to check if it is a compatible type, and you will not
> be able to do a typecast as there is no type name to typecast with.
>
> An open array is simply an exception for this rule, allowing you to skip the
> boundaries of the array.
>
> Michael._______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list