On 03 Apr 2013, at 16:25, Xiangrong Fang wrote:
It's because in Pascal you need to declare types first.
But why array[0..10] of Integer, or string[255] are not "types"?
They are type definitions. Parameter lists cannot contain type
definitions, only previously defined types. The main reason is that
defining the same structured type multiple types results in different
types. E.g.:
***
unit tt7;
interface
type
ta = array[0..10] of Integer;
tb = array[0..10] of Integer;
procedure test(a: ta);
procedure test(b: tb);
implementation
procedure test(a: ta);
begin
end;
procedure test(b: tb);
begin
end;
end.
***
The compiler can match the interface and implementation definitions
based on the fact that the type definitions match (note, "type
definitions" and not "type names" — i.e., you can add "type tc = ta"
and change the "a: ta" into "a: tc" only in the implementation, and it
will still compile because the type definitions still match).
However, if you would have
procedure "test(a: array[0..10])"
in the interface, there would be no way for the compiler to match the
implementation to the interface because in both cases a new definition
would be created. This is a fundamental aspect of how Pascal's type
system works.
Remember
that you can use "open array" in function params anyway.
An "open array" is a special case. It even can only appear inside
parameter lists, and there is no way to define a standalone "open
array" type.
Jonas
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal