[fpc-pascal] Re: type definitions etc

Florian Klaempfl F.Klaempfl at gmx.de
Sun May 29 09:57:19 CEST 2005


listmember wrote:
> Jeff Pohlmeyer wrote:
> 
>> To clarify, you can actually have many additional types between
>> the pointer type and the record definition, as long as you
>> don't introduce another section keyword that "turns off"
>> the current "type" section.
>> For instance, this will work:
>>
>>   type
>>
>>     pMyRec = ^tMyRec; // forward declaration
>>
>>     MyInt = integer;
>>     MyArray = array[0..255] of char;
>>
>>     { Hundreds more typedef's could go here }
>>
>>     tMyRec = Record // actual definition
>>       data:pointer;
>>       next:pMyRec;
>>     end;
>>
>>
>> But the next example will NOT work, because the additional "type"
>> keyword separates the two types:
>>
>>   type  pMyRec = ^tMyRec;
>>   type  tMyRec = Record
>>       data:pointer;
>>       next:pMyRec;
>>     end;
> 
> 
> I can see what you mean, but I fail see the wisdom
> behind the restriction.
> 
> Why should it matter if we used 2 'type' keywords
> instead of one --we are, after all, in the same
> declaration sestion of the same unit... Why should
> it matter?

type starts a new section without this restriction you could say why
doesn't work:

type
  precord = ^trecord

var
  r : trecord;

type
  trecord = record
  end;

It's simply the philosophy of pascal: things which need not to work
don't work. The extra type gives no gain, so why should be allowed? It
makes
- reading the code harder
- work for the compiler harder => slower and more error prone compiler

> 
> 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