[fpc-devel] Why: "Can't take the address of constant expressions" here?
Mattias Gaertner
nc-gaertnma at netcologne.de
Thu Jan 12 16:29:17 CET 2023
On Wed, 11 Jan 2023 23:58:34 +0100
Bart via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> Given the following program (an excerpt form a test program for a
> bugreport about the fpwidestring unit):
>
> ===
> program test;
> {$codepage utf8}
> {$mode objfpc}
> {$h+}
>
> uses
> FpWideString;
>
> var
> WSource: WideString = 'source';
> USource: UnicodeString = 'source';
> WDest: WideString = '' ;
> UDest: UnicodeString = '';
> ASource: AnsiString = 'source';
> ADest: AnsiString = '';
> P: array[0..99] of AnsiChar;
>
> begin
> with WideStringManager do
> begin
> writeln(1);
> Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
> CP_UTF8, Length(WSource));
> writeln(2);
> Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
> Length(ASource)); //<< test.lpr(24,53) Error: Can't take the address
> of constant expressions (caret behind UDest)
> end.
First of all, adding a 'end;" for the "with" compiles under Linux.
That's because widestring=unicodestring on Linux.
On Windows widestring is not a unicodestring and thus it can't be
passed to a var parameter.
https://wiki.freepascal.org/Widestrings
Mattias
More information about the fpc-devel
mailing list