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?
Are there any recommended workarounds for that?
Thanks, Adam
----------------------------------------------------------------------- C. Adam Oldham Marconi Commerce Systems Inc. Software Engineer 7300 West Friendly Ave. adam.oldham@marconi.com Greensboro, NC 27420-2087 Phone : 336.547.5952 Fax : 336.547.5079 ----------------------------------------------------------------------- This document contains confidential information of Marconi Commerce Systems Inc. In consideration of the receipt of this document, the recipient agrees not to reproduce, copy, use or transmit this document and/or the information contained herein, in whole or in part, or to suffer such actions by others, for any purpose except with written permission, first obtained, of Marconi Commerce Systems Inc., and further agrees to surrender the same to Marconi Commerce Systems Inc. upon demand. -----------------------------------------------------------------------
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