[fpc-pascal] Console Encoding in Windows (Local VS. UTF8)

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Jul 29 10:35:42 CEST 2013


On 29 Jul 2013, at 08:01, Noah Silva wrote:

> Oddly enough, I can get my (2.6.1) version to change the garbage it shows
> but but saving the file as UTF8 with BOM.  (Until now, I had been using
> UTF8 w/o BOM).

If your source code is in UTF8 but you do not tell this to the compiler, it will directly pass the "garbage" in your source code to the Win32 APIs. After all, there is no way for it to know what else it should with it, and instead has to assume that the programmer knows what he is doing.

> Detecting the Unicode BOM or not seems to be a strange way to switch the
> behavior of the compiler,

Why? A BOM unequivocally states the encoding of a file.

> I wonder why a $define wasn't used instead.

A directive is also available: http://www.freepascal.org/docs-html/prog/progsu88.html

And a command line parameter also (-Fc).

>> The ansi code page is (or at least can be) different, that's the the
>> result of
>>  function GetACP:UINT; stdcall; external 'kernel32' name 'GetACP';
>> 
> This is also 932, as expected.
> (I assume they should always be the same though, I don't think most
> programs check the console output page before writing).

Those programs would be wrong. A user can easily change the console output page with the "chcp" command.


Jonas


More information about the fpc-pascal mailing list