Pascal Viandier wrote:
Hello,
Thanks a lot for your suggestions.
However, by reading your answer I see no easy way to solve my problem.
In fact, there are to main patterns for using FillChar() in the code I work on: 1- Strings initialization as in the sample code bellow. For these cases, the first workaround you suggest works well and it is no big deal to change the code. 2- Records initialization. This is most of the FillChar() calls. The records (around 600 of them) are used to map on rows of tables in an Informix database. They contain various data types and strings as well. These strings are SUN Pascal Varying[n] Of Char. Internally, there are 4 bytes indicating the current string length and an Array of n Char. Since FillChar() is called with Chr(0) on them, this actually sets the current string length to 0 and fill them with zeroes. In this case, I think the best approach will be to generate procedures to do the records initialization field by field and call them instead of FillChar(). With a moderate amount of work, my translation program should be able to take care of this.
It seems to me that Extended Pascal's initial-state-specifier would be the ideal solution for your problem. Initial-state-specifiers are designed to exactly what you're try to accomplish here with you're hackish use of FillChar() and have the additional benefit of correctly initializing a variable of any Pascal type without needing to worry about the implementation pecularities.
You can use initial-state-specifiers in any type or variable declaration. When used in a type declaration, any variable of that type unless overridden by a initial-state-specifier in the variable declaration will be initialized to the specified initial state upon activation of the block containing the variable declaration. When used in a variable declaration, the declared variable(s) will be initialized to the specified initial state upon activation of the block containing the variable(s) declaration.
Some examples:
type PsuedoStr10 = record length: cardinal; chars: packed array [1..10] of char; end value [length: 0; chars: [1..10: chr(0)]]; var FakeStr10: PsuedoStr10; {initialized to length = 0 and all chars elements to chr(0)} AsteriskStr10: PsuedoStr10 value [length: 10; chars: [otherwise '*']]; {initialized to length = 10; all chars elements to '*'}
Note: The initial-state-specifiers "chars: [1..10: chr(0)]" and "chars: [otherwise '*']" both initialize 10 elements in this particular example. For an all array elements initial-state-specifier, "chars: [otherwise '*']" is preferrable since it will automaticly adjust to any changes to the array size in the chars field type declaration.
I believe Extended Pascal's initial-state-specifiers are supported in the latest GPC version but I haven't actual tested it.
Gale Paeper gpaeper@empirenet.com