[fpc-pascal] private type and type compatibility
Sven Barth
pascaldragon at googlemail.com
Wed Oct 30 15:00:41 CET 2013
Am 30.10.2013 14:37, schrieb Jonas Maebe:
>
> On 30 Oct 2013, at 14:30, Xiangrong Fang wrote:
>
>> 2013/10/30 Jonas Maebe <jonas.maebe at elis.ugent.be>
>>
>>> The tdynarray type is not visible in the program because u1 is not
>>> in its
>>> uses clause (it's not in scope whatsoever), and nevertheless there
>>> is no
>>> problem to use it. It's of course not exactly the same (tdynarray isn't
>>> declared as private to u1), but at the scope visibility level it is the
>>> same situation as far as I am concerned.
>>
>> I don't think they are the same. tdynarray
>> is not usable in main program because you did not uses u1, NOT
>> because the
>> type is defined as PRIVATE!
>
> "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. The same should be the case for
private type declarations used in public ones...
Regards,
Sven
More information about the fpc-pascal
mailing list