[fpc-devel] Array of char

Stefan Glienke sglienke at dsharp.org
Wed Feb 25 18:41:32 CET 2015

Maybe in D7 this works and in Delphi XE7 you also can get away with it when
passing it directly to Writeln but this will throw a nice AV and the end:

program Project1;
   Str = 'TEST';
   Data: array of Char;
   s: string;
   SetLength(Data, Length(Str));
   Move(Str[1], Data[0], Length(Str)*SizeOf(Char));
   s := string(Data);

I debugged into the code (it's calling UStrAsg) and what it does cannot 
be correct because it
interprets the array of Char directly as string messing around with its 


Am 25.02.2015 um 17:02 schrieb thaddy at thaddy.com:
> @ Florian.
> You closed the typecast from array of char to string issue.
> Maybe you are right,
> I just can prove that every d2-xe7 adds a #0, so a cast (partially, 
> agreed) works in delphi and not in fpc.
> I suggest you reconsider this. The raw pointer cast should work, which 
> means an array of char should have a hidden terminator as well as a 
> hidden pre.
> With all respect,
> Thaddy
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20150225/7419e07b/attachment.html>

More information about the fpc-devel mailing list