Oldham, Adam wrote:
Another question from the documentation:
Section 6.12: "GNU Pascal knows Borland Pascal's procedures FillChar and Move. However, their use can be dangerous because it often makes implicit unportable assumptions about type sizes, endianness, internal structures or similar things. Therefore, avoid them whenever possible. E.g., if you want to clear an array of strings, don't `FillChar' the whole array with zeros (this would overwrite the Schema discriminants, see section 8.13.14 BP compatibility: Strings), but rather use a `for' loop to assign the empty string to each string. In fact, this is also more efficient than `FillChar', since it only has to set the length field of each string to zero."
What is your recommended fix if you call FillChar on a record, and that record contains the string. Even if you do a for loop to fill the record with 0's, you will still overwrite the schema, correct?
Yes.
Are there any recommended workarounds for that?
Simply assign "0" to all fields (or rather, those fields that need to be initialized, which are often not all).
Though you might have to type a few more lines, this will often be faster (see above) and also make sure that the "correct" 0 is used. E.g., a real zero (0.0) is not necessarily a 0 bit pattern, and for subranges not including 0 (or the corresponding char, boolean or enum value), "0" would be our of range.
Frank