makervef.blogg.se

Free pascal pointer record array
Free pascal pointer record array











  1. #FREE PASCAL POINTER RECORD ARRAY HOW TO#
  2. #FREE PASCAL POINTER RECORD ARRAY CODE#

I hope I can explain this in a way that is understandable. Hopefully that takes care of the confusing part of "packed"/"unpacked" when applied to arrays. I have attached a very simple little program that shows that "packed"/"unpacked" has no effect on an array definition (at least not in FPC/Delphi) but has a significant effect on the elements of the array (when they are records.) That will determine the size of the element which the compiler needs to calculate the address of each element. These days, what the compiler really cares about is whether the array elements (records) are packed or not. Today, it's rare to see a Pascal compiler where "packed"/"unpacked" have an effect on array definitions.

free pascal pointer record array

(a bit like IBM's packed and unpacked BCD) The original Pascal included facilities to "pack" and "unpack" to take data from a hard-to-use packed state to a simpler/easier "unpacked" state. It was necessary to let the compiler know of this which was done through the use of "packed" in front of a character array. Quite often characters were "packed" together.

free pascal pointer record array

It used to be that a single character wasn't always represented by an 8 bit byte. Once the compiler knows the alignment and the alignment of the individual elements matches the alignment of the structure pointer, you go to town.

#FREE PASCAL POINTER RECORD ARRAY HOW TO#

There are ways to work around that, (I don't know how to do it in Pascal/FPC) but, in C/C++ you can tell the compiler the alignment for each individual record then you can declare a pointer to the first record/structure including its alignment. In many cases, the alignment will be wrong because the compiler had no idea the 10 record declarations were to be part of an array. The fast way of getting in trouble is to declare some records (say 10 for example's sake) and then _overlay_ an array of records of that type over them.

free pascal pointer record array

#FREE PASCAL POINTER RECORD ARRAY CODE#

In both cases, the compiler knows it's dealing with an array and as long as it knows that, the generated code should be correct. IOW, the following should be an identity maintained by the compiler : ArrayBase = (ArrayBase + Index)^. As long as you don't "lie" to the compiler, addressing through pointers or indexing should _functionally_ be the same.













Free pascal pointer record array