Discussion:
type pointer to record before record.
(too old to reply)
Skybuck Flying
2011-04-28 18:56:57 UTC
Permalink
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.
spacetime
2011-05-28 20:35:27 UTC
Permalink
Post by Skybuck Flying
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
type
    PMyRecord = ^TMyRecord;
    TMyRecord = record
        mSelf : PMyRecord;
        mNext : PMyRecord;
    end;
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".
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... )
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.
1. This is how it works under Turbo Pascal:
During type declaration block processing Turbo Pascal stores pointer
types to temporary symbol table.
After the type declaration block has been processed it resolves
pointer references to types.

check
http://turbopascal.org/processing-type-declarations
http://turbopascal.org/processing-non-object-types

2. Well, it would be possible but I see no need for this.

3. Yes

4. No

5. I don't support this way of language relaxation....

Igor

Loading...