[fpc-devel] Constant arrays sometimes produce incorrect data tables

David Butler david at e.co.za
Sun Aug 14 00:27:52 CEST 2005


Hi Anton

Thanks for the suggestion.

I checked this by changing String to AnsiString, both in the
declaration and where the array is accessed, but it still compiles
differently in the two units.

It seems that where the usual pattern is to store the table as "Ptr,
Ptr, Ptr, ..., Value, Value, Value, ...", in this case it stored as
"Ptr, Value, Ptr, Value, Ptr, Value, ...".

Regards
David

On Sun, 14 Aug 2005 01:10:11 +0200, you wrote:

>>const
>>  RFCMonthNames : Array[1..12] of String = (
>>    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
>>    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
>>
>>is usually assembled as something like:
>>
>>TC_P$TESTARRAY_RFCMONTHNAMES
>>DD _$PROGRAM$_L4, _$PROGRAM$_L5, _$PROGRAM$_L6, _$PROGRAM$_L7, ......
>>DD -1,3
>>_$PROGRAM$_L4: DB "Jan",0 DD -1,3
>>_$PROGRAM$_L5: DB "Feb",0 DD -1,3
>>....
>>
>>which is correct, but the exact same code (in a different unit) is
>>compiled differently, causing access violations when accessed:
>>
>>TC_CDATETIME_RFCMONTHNAMES
>>DD _$CDATETIME$_L2046
>>DD -1,3
>>_$CDATETIME$_L2046:
>>DB "Jan",0
>>DD _$CDATETIME$_L2047
>>DD -1,3
>>_$CDATETIME$_L2047:
>>DB "Feb",0
>>DD _$CDATETIME$_L2048
>>DD -1,3
>>_$CDATETIME$_L2048:
>>DB "Mar",0
>>DD _$CDATETIME$_L2049
>>DD -1,3
>>_$CDATETIME$_L2049:
>>DB "Apr",0
>>........

>There are two kinds of strings, shortstrings (max. 256 bytes) and 
>ansistrings (any length, allocated on the heap). May be they're mixed, 
>because the declaration "string" might use a shortstring in one unit, an 
>ansistring in another, depending on compiler switches like "$H" or 
>"$LONGSTRINGS".
>Such mixing would very likely cause access violations. Try e. g. to 
>change all declarations to "shortstring", which is enough for short 
>month names.





More information about the fpc-devel mailing list