[fpc-devel] type pointer to record before record.

Skybuck Flying skybuck2000 at hotmail.com
Thu Apr 28 20:56:03 CEST 2011


Hello,

In free pascal/pascal/delphi it's necessary to declare a pointer to a 
record, which is to be used inside the record to point to itself, before the 
record itself without a type directive in between them for example:

// correct:
type
    PMyRecord = ^TMyRecord;
    TMyRecord = record
        mSelf : PMyRecord;
        mNext : PMyRecord;
    end;

// incorrect/not allowed:
type
    PMyRecord = ^TMyRecord; // above type anywhere else.

type
    TMyRecord = record
        mSelf : PMyRecord;
        mNext : PMyRecord;
        mPrev : ^TMyRecord; // not allowed.
    end;

    PMyRecord = ^TMyRecord; // below anywhere else

// and so forth...

I would first like to remark about this: "This is very newb unfriendly... 
newbs might not know this... and will get frustrated by this 
weird/odd/non-intuitive language construction".

Now some question about this:

1. Is there a compiler-related technical reason why it has to be like this ? 
If so explain shortly...

2. Is there perhaps a technical solution for it so this is no longer 
required ? If so how much effort would a solution cost ?

3. (Does free pascal still follow these restrictions ? I guess so... )

Final question assuming it's solvable::

4. Do you think it's worth to solve this oddity and make the language more 
newb friendly and more intuitive ?

5. Would it break anything ? (I think not... it would be an 
extension/relaxation of the language...)

Bye,
  Skybuck. 




More information about the fpc-devel mailing list