[fpc-pascal] private type and type compatibility

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Oct 30 15:34:01 CET 2013


On 30 Oct 2013, at 15:00, Sven Barth wrote:

> Am 30.10.2013 14:37, schrieb Jonas Maebe:
>>
>> "Private" is just another way to define a scope, just like a unit  
>> interface and implementation define a scope. Neither the "private"  
>> section nor the interface of unit "u1" is in scope when the  
>> "hidden" type is used.
> Using an interface uses as the analog for private types is flawed in  
> my opinion. The analog code would more like this:
>
> === code begin ===
>
> unit u2;
>
> interface
>
> function f: tdynarray;
>
> implementation
>
> type
>  tdynarray = array of integer;
>
> function f: tdynarray;
> begin
>
> end;
>
> end.
>
> === code end ===
>
> Which of course does not compile.

This is not equivalent. A private type declaration in a class adds a  
new identifier that is visible inside that class. You then use it,  
still in that class, to declare the return type of a function. Next,  
in a scope where that type identifier is no longer visible, you call  
the function.

My example is a complete match to that scenario as far as identifier  
visibility is concerned (you use a type in a scope where it is visible  
to declare a function return type, and then call the function in a  
scope where it is not visible). In your example, the type is not  
visible in the place where the function is declared but only where it  
is defined.


Jonas



More information about the fpc-pascal mailing list