[fpc-pascal] Is it save to think default value of untouched string is ''?

lyh1 lyh1win at hotmail.com
Sat Mar 6 21:13:48 CET 2010

I have a a program that will read a string and parse the string to some
sub-strings in sub routine.
I add every character to a local string buffer  in sub routine. The code
work well in delphi but suddenly fail in fpc.
When I watch the buffer, it display some garbage instead of null string when
the buffer is untouched.
The following output is supposed to be 1(and it is true here), but in more
complicated situation it is not true. You may get 'bla bla bla 1'.

procedure PrintString;
var str1 : string;
  procedure createContent(var buf : string);
   var str2 :string;
     buf := str2;
     buf := buf + '1';


My question is we should always assign null string to variable before use or
this a bug if I get garbage in unused string?

More information about the fpc-pascal mailing list