[fpc-devel] fpc compiler wrong encoding in console output on Windows

Tomas Hajny XHajT03 at hajny.biz
Wed Aug 30 15:57:16 CEST 2023


On 2023-08-30 13:49, Mattias Gaertner via fpc-devel wrote:
> On 30.08.23 12:04, Tomas Hajny via fpc-devel wrote:
>> On 2023-08-28 15:53, Ondrej Pokorny via fpc-devel wrote:
>> [...]
>> Your output is different from mine (using a freshly compiled trunk 
>> compiler):
>> Free Pascal Compiler version 3.3.1 [2023/08/29] for i386
>> Copyright (c) 1993-2023 by Florian Klaempfl and others
>> Target OS: Win32 for i386
>> Compiling t2.pas
>> t2.pas(4,2) Note: User defined: ä
> 
> Then you don't have default windows setup. Maybe you installed the cp 
> 65001?

Default setup of what exactly? I didn't install anything special, but my 
MS Windows installation indeed supports CP 65001. I guess that it may be 
different for different MS Windows versions - specifically, I tested it 
on MS Windows 10 Enterprise version 22H2. However, that shouldn't make a 
difference, because Ondrej stated that he gets compiler output in UTF-8, 
but I also tried redirecting the output to a file and the result is in 
CP852 which is my default "ANSI" codepage (and thus also the default 
console codepage). There's no place where UTF-8 availability might 
change the result in this. However, I _didn't_ test it under Lazarus. I 
suspect that Lazarus messing with the codepages may change the behaviour 
by changing either the system codepage or console codepage to UTF-8 and 
this then results in compiler emitting output in this different codepage 
(i.e. UTF-8).


>> [...]
>> However, I run the compiler from regular command line, not from 
>> Lazarus.
> 
> I get the same in cmd.exe and via TProcess.

I.e. you open cmd.exe e.g. via the Windows key+R (rather than by 
shelling from Lazarus)?


>> [...] What do you get when running the following test program (you can 
>> simulate the same conditions e.g. by naming the resulting binary 
>> fpc.exe and configuring Lazarus to use this "compiler"):
>> 
>> uses
>>   Windows;
>> begin
>>   WriteLn (GetACP);
>>   WriteLn (GetConsoleCP);
> 
> ACP is 1252
> ConsoleCP 437

Just to be sure - you get this when running the test from Lazarus as a 
"compiler" (as suggested in my note above)?

Tomas


More information about the fpc-devel mailing list