let OUT = " ■ " # U+25A0, file stored in UTF-8 format
for i in 0..5: echo OUT
for i in 0..5: write(stdout, OUT)
under Windows 7 (64 bit, CP65001), is the exception sth. I should expect?
Is there an echo() w/o linefeed btw. (didn't find it though...)?
One cannot compare Linux/Mac OS X with Windows when it comes to UTF-8 output, as there are too many differences. So the fact that it is working there doesn't come at a surprise ;-)
Wat nu?
EDIT: The point is echo(...) which supposedly should be sth. like write(stdout, ...) works differently as I would expect it (the latter command even crashes). If however write(stdout, ...) isn't echo(...) w/o the linefeed, what is it's write() counterpart (or vice versa)?
Did you look in the generated code? On OS X (and yes I know they work differently) I get basically the following:
{
NI res_88025;
res_88025 = 0;
{
while (1) {
if (!(res_88025 <= 5)) goto LA4;
i_88017 = res_88025;
printf("%s\012", out_88003? (out_88003)->data:"nil");
res_88025 += 1;
} LA4: ;
}
}
{
NI res_88055;
res_88055 = 0;
{
while (1) {
if (!(res_88055 <= 5)) goto LA7;
i_88049 = res_88055;
write_13261(stdout, out_88003);
res_88055 += 1;
} LA7: ;
}
}
So it is just using printf. But I guess that will be the same on windows and that this does some magic? Which would mean you could at least resort to call printf from Nim?
let OUT = "[■]" # U+25A0, file stored in UTF-8 format
echo OUT
write(stdout, OUT)
gives me:
[■]
[■]Traceback (most recent call last)
test2.nim(4) test2
system.nim(2239) raiseEIO
Error: unhandled exception: cannot write string to file [IOError]
Please note the last line.
Compiling the following C code (as extracted from the generated C source test2.c):
#include <stdio.h>
char *OUT = "[■]"; // U+25A0, file stored in UTF-8 format
void main() {
printf("%s\n", OUT);
fwrite(OUT, 1, 5, stdout);
}
gives me (CP 65001 active):
[■]
[■]
So, it seems the general setup (using printf/fwrite) is correct. There must be something wrong after fwrite().