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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.