I've been using this for so long that I forgot about it. A colleague coming from C# asked how you can declare a pointer to a type that you haven't defined as yet.

I've been using this for so long that I forgot about it. A colleague coming from C# asked how you can declare a pointer to a type that you haven't defined as yet.

Like

Type
TMyPtr = ^TMyRecord;
TMyRecord = Record
MyField : integer;
end;

I just told him Pascal magic, because in some other cases you may need a "forward" statement, but not with pointers. Does anyone know the history behind why this was done? I mean, you COUL define the TMYRecord record type before you declare the TMyPtr;

Comments

  1. Nothing to write home about here. Only if the type uses that pointer type does it get interesting.

    ReplyDelete
  2. Today, this is legal

    TRec = record
    Next: ^TRec;
    end;

    as is

    TRec = record
    type
    PRec = ^TRec;
    var
    Next: PRec;
    end;

    ReplyDelete

Post a Comment