[fpc-devel]Pchar issue on Win32 with 1.9.2

Skovrup, Morten Juel ms at mek.dtu.dk
Fri Jan 16 14:40:47 CET 2004


OK Thanks!

I didn't find the exact place in the documentation, but this is a change
in behaviour right? It worked in earlier versions of FPC and it works in
Delphi...

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




More information about the fpc-devel mailing list