[fpc-pascal] PChars and AnsiString Code Pages

Jonas Maebe jonas.maebe at elis.ugent.be
Wed May 18 19:29:01 CEST 2016


Tony Whyman wrote:
>
> While the online documentation says a lot about tyepcasting PChars to
> AnsiStrings, there seems to be nothing on the reverse.

You obviously meant the opposite. In any case, ansistring(pchar) results 
in the same code as ansistring:=pchar, and results in a type conversion 
that creates a new ansistring from scratch based on the pchar data.

Re-interpreting a pchar pointer as an ansistring would probably crash in 
any FPC version, but that will not happen here because pchar and 
ansistring are assignment compatible. I.o.w., the typecast is 
superfluous. Everything that works without a typecast is supported by 
definition (barring bugs).

The documentation indeed appears to contain no information about which 
string types and related types are assignment compatible (and, a 
fortiori, can also be typecasted into each other). Char, shortstring, 
(non-dynamic) array of char etc can all also be assigned to ansistrings.


Jonas



More information about the fpc-pascal mailing list