[fpc-pascal] more questions on storage

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Sep 27 14:06:19 CEST 2007

On Thu, 27 Sep 2007 12:38:13 +0200 (CEST)
marcov at stack.nl (Marco van de Voort) wrote:

> > marcov at stack.nl (Marco van de Voort) wrote:
> > > A cast is really a cast. IOW the cast pchar(ansistring) is mostly
> > > a no-op. Traditional C code then usually treats the #0 as end of
> > > string. 
> > 
> > PChar(AnsiString) was a no-op typecast in the past and is nowadays a
> > function. It checks whether the AnsiString is nil and if yes
> > returns a pointer to a string containing one character: #0.
> > 
> > That means:
> > Pointer(AnsiString) <> Pointer(PChar(AnsiString))
> > 
> > To get a no-op typecase you can use:
> > MyPChar:=PChar(Pointer(AnsiString));
> Is this delphi compat, and if yes, what is this exactly for?

I don't know.

The change broke some lazarus code and now it is polluted by the ugly
double type casts, just to get some no-op type casts.
Because this fact is not widely known or often forgotten, many use the
PChar() as simple type cast. That's why the lcl interfaces already got
into troubles several times, so everytime we get strange errors I first
search for these typecasts.
Maybe we should mention this fact at a more prominent place in the
wiki and docs.


More information about the fpc-pascal mailing list