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

Florian Klaempfl florian at freepascal.org
Sun May 29 21:15:57 CEST 2005


listmember wrote:

> Florian Klaempfl wrote:
> 
>>> I am not sure it is one of those things that need not work.
>>
>>
>> What would be the gain?
> 
> 
> Unless the compiler generates some sort of hint, or warning;
> the loss (i.e. negative gain) is a needlesly confused developer.

No, he should simply know the language he uses. Understanding the
concept of forward declarations is harder than to understand that they
must be in the same type block.

Anyways, it's how pascal works and there is absolutely no need to
support it. Or do you think british people are confused by the fact that
they have to use program instead of programme?

> 
>>> Interesting... this little bit of flexiblity would make
>>> life that hard for the compiler?
>>
>>
>> Well, don't forget that adding more flexibility could also be 
> 
>> abused, if you example worked, why shouldn't
> 
>>
>> type
>>  pMyRec = ^tMyRec;
>>
>> var
>>   i :longint;
>>
>> type
>>   tMyRec = Record
>>     data:pointer;
>>     next:pMyRec;
>>   end;
>>
>> work. 
> 
> 
> IMHO it should work too :-)
> 
> After all, all these declarations are in the same unit, so we
> do not have any namespace conflicts to worry about.
> 
> Is there any reason that forward declarations be immediately
> above or below what they refer to?

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 ;)
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? It could be valid with the same arguments because if it
doesn't work people could get confused.

> 
>> There is simply a limit in flexibility where it gives no extra
>> gain anymore.
> 
> 
> Should I understand this as something to do with the current
> compiler being written from ground up; i.e. some features
> will be added as the codebase matures?
> 
>>> So, these 2 different forms are theated differently by the
>>> compiler too?
>>>
>>> This:
>>>
>>> const SOME_NUMBER1 = 1;
>>> const SOME_NUMBER2 = 2;
>>> const SOME_NUMBER3 = 3;
>>> const SOME_NUMBER4 = 4;
>>>
>>> and this:
>>>
>>> const
>>>  SOME_NUMBER1 = 1;
>>>  SOME_NUMBER2 = 2;
>>>  SOME_NUMBER3 = 3;
>>>  SOME_NUMBER4 = 4;
>>
>>
>> Internally of course, the second is compiled faster, you won't 
> 
>> notice it though in this example ;)
> 
> Yes, but both are allowed..
> 
> Cheers,
> Ray
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list