[fpc-devel] Strange Problem!
amir at aavani.net
Wed Apr 25 23:53:15 CEST 2012
> 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.
Why does fpc consider the constant string ' ' as an ansistring, not
a shortstring? What fpc did, in this case, is not what I expected.
More information about the fpc-devel