[fpc-pascal] pointer to char vs pchar

Michael Van Canneyt michael at freepascal.org
Fri Mar 24 21:11:03 CET 2023



On Fri, 24 Mar 2023, Peter B via fpc-pascal wrote:

> On 24/03/2023 14:29, Martin Frb via fpc-pascal wrote:
>> On 24/03/2023 15:04, Benito van der Zander via fpc-pascal wrote:
>>> why is a pointer to a char not a pchar (for type helpers)? 
>> 
>> My guess: For the same reason that "p2" fails in the below. Distinct type.
>> May be assignment compatible, but a type of it's own.
>
> My understanding is that pchars are supposed to be null terminated,
> while the char in a pointer to a char might not be.

This is not quite correct.

By itself, a PChar can point to anything. 
Only if you typecast a valid ansistring to a pchar then the result of the
typecast is guaranteed to be null-terminated.


Michael.


More information about the fpc-pascal mailing list