[fpc-pascal] Records

Carsten Bager carsten at beas.dk
Wed Oct 26 10:06:26 CEST 2005


> Adriaan van Os wrote:
> 
> > Carsten Bager wrote:
> > 
> >> We are moving a lot of code from an old platform where it is
> >> allowed to compare 2 records like this.
> >>
> >> Type
> >>   A_typ=array[0..3] of integer;
> >> Var
> >>  A1,A2:A_typ;
> >>
> >> Begin
> >>   If A1=A2 then
> >> End;
> >>
> >> I know that I can typecast to an array of char to compare but
> >> is there an easier way.
> >>
> >> ---
> >>
> >> I have never could understand when this is allowed
> >> A1:=A2;
> >>
> >> Why this is not allowed
> >> If A1=A2 then
> >>
> >> in most Pascal compilers.
> > 
> > 
> > Because you can't simply compare the memory ranges occupied by records A
> > and B. They could have different pad bytes (and bits) but still be the
> > same. Therefore, implementation is non-trivial. For the same reason, the
> > above typecast is incorrect.

I have never used this without initializing records first 
(A1:=A2). I have used it on deferent platforms (on  PC's with 
typecast). It has all ways don what I expected.
It could be a demand that records should be packed, but 
that triggers another problem on some (ARM) platforms.

> > 
> 
> We could implement such a comparisation based on rtti ...

I assume that rtti means "Runtime Type Information", 
something a have never used, but if it can do the job I would 
be happy.

Regards Carsten



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