[fpc-devel]Pchar issue on Win32 with 1.9.2

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


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
>




More information about the fpc-devel mailing list