[fpc-devel]Pchar issue on Win32 with 1.9.2

Michael Van Canneyt michael.vancanneyt at wisa.be
Fri Jan 16 14:55:37 CET 2004


On Fri, 16 Jan 2004, Skovrup, Morten Juel wrote:

> OK Thanks!
>
> I didn't find the exact place in the documentation, but this is a change
> in behaviour right?

No, it was always like that.

> It worked in earlier versions of FPC and it works in Delphi...

This is pure coincidence. The change in the register allocator just
exposes a bug in your code. Delphi documentation also warns against
this...

Michael.

>
> Regards
> Morten
>
> -----Original Message-----
> From: fpc-devel-admin at lists.freepascal.org
> [mailto:fpc-devel-admin at lists.freepascal.org] On Behalf Of Michael Van
> Canneyt
> Sent: 16. januar 2004 14:29
> To: fpc-devel at lists.freepascal.org
> Subject: Re: [fpc-devel]Pchar issue on Win32 with 1.9.2
>
>
>
>
> On Fri, 16 Jan 2004, Skovrup, Morten Juel wrote:
>
> > I couldn't get in contact with the bug-report system, but the
> > following code behaves incorrectly (compiled using -Sd):
>
> No, it is correct.
> The result of a PChar() typecast on an expression is not defined outside
> the expression. This is correct behaviour - maybe unexpected. You must
> explicitly assign the expression result to a string, and typecase that.
>
> This is documented behaviour!
>
> Michael.
> >
> > program TestConsole;
> >
> > var
> >   AStr,BStr : string;
> >
> > procedure WriteStr(p1,p2 : PChar);
> > begin
> >   WriteLn(p1,p2);
> > end;
> >
> > begin
> >   AStr := 'Hel';
> >   BStr := 'Hi';
> >   //The following outputs 'Hello Hello'
> >   WriteStr(PChar(AStr+'lo '),PChar(BStr+'Hi'));
> >   //The following outputs 'Hello Hi Hi'
> >   WriteStr('Hello',' Hi Hi');
> >   ReadLn;
> > end.
> >
> > Regards
> > Morten
> >
> > _______________________________________________
> > fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-devel
> >
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>




More information about the fpc-devel mailing list