[fpc-devel] Strange Problem!

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Apr 26 00:05:05 CEST 2012


On 25 Apr 2012, at 23:53, Amir wrote:

>> The reason is that ansistring is an implicit pointer type, unlike shortstring. Assigning a constant ansistring to Result means simply that a pointer to that series of spaces is copied into the Result pointer. If you then start modifying Result by hacking behind the compiler's back (which is what you do by using a pointer), the compiler cannot make a copy of that constant string and you start modifying the original constant data that was stored in the program. As a result, when you call the function again, the first assignment will assign whatever you stored in that constant during the previous execution of your function rather than a series of spaces.
> 
> Makes sense!
> Why does fpc consider the constant string '     ' as an ansistring, not a shortstring?

Because your function is declared as returning an ansistring.


Jonas




More information about the fpc-devel mailing list