I am a novice gpc user trying to port some code from an old Unix compiler to gpc. We have the following scattered throughout the code. Most of this code was written before I got here, so I take no credit.
PString = STRING[255]; pPString = ^PString; . . . PPtr : pPString; . . . PPtr^ := ''; . . . PPtr^[0] := CHR(I);
gpc is complaining about the PPtr^[0] line. If I change it to say "PPtr^ := CHR(I);" the compiler is happy, but we use this method several times to get the length of arrays or strings. Is there anyway to get gpc to allow this or does it violate the Pascal standard?
-Jason
Moore, Jason wrote:
I am a novice gpc user trying to port some code from an old Unix compiler to gpc. We have the following scattered throughout the code. Most of this code was written before I got here, so I take no credit. [...] PPtr^[0] := CHR(I);
This works in UCSD and Borland Pascal but violates ISO 10206 Extended Pascal standard. It depends on the length of the string stored in the zeroth character - which is not the case in GPC which reserves (on 32-bit machines) four bytes for the length of the string.
The correct solution is to set the length of the string with the `SetLength' procedure:
SetLength ( PPtr^, I );
Hope this helps,
Peter