Hi,
A C library that I'm accessing from perl (via XS) conditionally might attempt to print out ± or ∞.
The library code attempts to do this by passing the infinity or the plus-or-minus as a string literal to fprintf().
If the filehandle is stdout, then these symbols are being displayed by my Windows perls as garbage.
No such problem on Linux ... and no such problem with perls running under Cygwin on the very same Windows 11 box. All works there as intended.
In fact, it's also fine on the Windows system if the output filehandle is to a file, or if I redirect the output to a file (rather than allowing it to go to the cmd.exe console)
By way of demonstration, I have the following Inline::C script
use strict;
use warnings;
use utf8;
use Inline C => <<'EOC';
void wprint () {
printf("+ or - : ±\n");
}
void foo () {
unsigned char a = '±';
printf("%d\n", a);
}
EOC
wprint();
foo();
For me, that outputs:
+ or - : ▒
177
The question is:
Leaving the C code as it is, how do I get the plus-or-minus symbol to display as intended on Windows (cp437 or cp850) when the display is being sent to stdout ?
I thought this would easy ... but not for me. Even using Text::Iconv (which I'm sure that I once understood) is doing nothing. So, FAIK, it might not even be possible ?? (Is it something that can only be handled within the C code ?)
And using stuff that I
don't understand (like
use open ':std', ':encoding(cp437)') is also having no effect, irrespective of whether I specify cp437, cp850 or cp1252.
According to
chcp, my Windows 11 codepage is cp437. On my Windows 7, where the same issue arises, the codepage is cp850.
Any help is much appreciated.
Cheers,
Rob