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

Anton Tichawa anton.tichawa at chello.at
Sun Aug 14 01:10:11 CEST 2005

David Butler wrote:

>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:
>  RFCMonthNames : Array[1..12] of String = (
>    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
>    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
>is usually assembled as something like:
>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:
>DD -1,3
>DB "Jan",0
>DD -1,3
>DB "Feb",0
>DD -1,3
>DB "Mar",0
>DD -1,3
>DB "Apr",0
>fpc-devel maillist  -  fpc-devel at lists.freepascal.org
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 
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