[fpc-pascal] Re: type declarations [was Re:]

listmember listmember at letterboxes.org
Sun May 29 22:17:51 CEST 2005


> So this is ok as well:
> 
>  type
>   pMyRec = ^tMyRec;
> 
>  var
>    i :tMyRec;
> 
>  type
>    tMyRec = Record
>      data:pointer;
>      next:pMyRec;
>    end;
> 
> I see no reason why it should work ;)

You're taking the analogy too far now :-)

The compiler should get back with a message saying "Error:
tMyRec is not fully defined yet" at the point where the
code has

   var
     i :tMyRec;

> and:
> 
>  type
>   pMyRec = ^tMyRec;
> 
>  var
>    i :tMyRec;
> 
>  procedure p;
>    begin
>      i.data:=nil;
>    end;
> 
>  type
>    tMyRec = Record
>      data:pointer;
>      next:pMyRec;
>    end;
> 
> is ok as well? 

No, not OK.

Here, when the compiler meets

  var
    i :tMyRec;

it should emit a 'not fully defined yet' error and stop.

Once it stops, it never reaches 'procedure p' anyway,
so we need not discuss that case.

In short, as long as the compiler catches 'not fully defined
yet' stuff, I have no issues with where and how far apart they
are forward declared.

> It could be valid with the same arguments because if it
> doesn't work people could get confused.

AFAIK, there is no restriction wrt vicinity of forward declarations
--as long as they are in (or belong to) the same unit (namespace).

And, yes, of course, you're not supposed to declare/use a variable
unless it is fully defined.

But, here we are talking about variable decalarations, not type
decalarations.





More information about the fpc-pascal mailing list