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

David Butler david at e.co.za
Sat Aug 13 23:45:15 CEST 2005


Hi all

I picked up this weird code generation problem (it was also present in
2.0.0). I reported it as bug 4277 today. Unfortunately I can only
reproduce it in a specific context, so please e-mail me for the unit.

The problem is when you define an array of constant strings.

For example:

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
........


Regards
David





More information about the fpc-devel mailing list