[fpc-pascal] Re: weird compile error message

Sven Barth pascaldragon at googlemail.com
Thu Sep 12 07:18:46 CEST 2013


Am 12.09.2013 03:14 schrieb "Xiangrong Fang" <xrfang at gmail.com>:
>
> Hi Sven,
>
>> Additional note: The "PTree = ^TTree" in front of the "TTree" is wrong
and only supported by pre-2.7.1 FPC by accident. The correct code would be:
>
>
> I removed PTree yesterday and this problem is gone.  I now understand
that it is not necessary to define PTree as TTree is a pointer anyway.
However, I don't understand why it is WRONG.  I mean, is the problem I
reported caused by this definition? If so, why it disappeared while the
debug-info-generation option is turned off?
>
> Say, the following is normal in pascal:
>
> type
>   PMyRecord = ^TMyRecord;
>   TMyRecord = record
>       ... ...
>   end;
>
> Why it is wrong to define PTree = ^TTree?   Is it because that this kind
of pointer definition is:
> only valid for record, but not class?
> only valid for record and NON-generic class?

It is wrong, because the type "TTree" does jot exist. Only "TTree<T>". But
you can not use that before the generic is declared, because the "T" would
be unknown then and also when specializing the compiler would not be able
to know that it would need to somehow specialize "PTree" as well as it does
not know (from the perspective of "TTree") that something is pointing at
"TTree". That's why you need to declare "PTree" inside the generic (this
was one of the reasons why nested types were added).

And this reason combined with a bug in the compiler resulted in your error
message. The 2.7.1 compiler will present you the error that the usage of
generics without specialization is not allowed.

Otherwise pointers to classes are principally allowed, but I don't see a
use in them, because classes are already pointers.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130912/6eca14d4/attachment.html>


More information about the fpc-pascal mailing list