[fpc-pascal] PChars and AnsiString Code Pages

Tony Whyman tony.whyman at mccallumwhyman.com
Wed May 18 10:32:23 CEST 2016


I've been looking at some old code which still seems to work in fpc 
3.0.0 - but is it safe? The code looks like:

{$mode delphi}

var Buf: PChar;
       s: string;
begin
   Buf := LoadString; {returns a pointer to an arbitrarily long null 
terminated string}

   s := string(Buf); {seems to work - but should it?}
end;

The above has been around since Delphi days and has never caused 
trouble, but I am certainly wondering if this coercion is safe anymore 
given the introduction of AnsiString code pages.

Any ideas?



More information about the fpc-pascal mailing list