Issue 8600 - "writeln" one parameter garbled
Summary: "writeln" one parameter garbled
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2012-08-30 04:57 UTC by Lo
Modified: 2024-12-01 16:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lo 2012-08-30 04:57:50 UTC
import core.stdc.wchar_,core.stdc.locale;

example code:

extern(C) int setlocale(int, char*);   
static this()   
{   
    fwide(core.stdc.stdio.stdout, 1);   
    setlocale(0, cast(char*)"china");      
}
int main(string[] argv)
{
   writeln("1个");
   return 0;
}


Temporary fix:

void writeln(T...)(T args)
{
    static if (T.length == 0)
    {
        enforce(fputc('\n', .stdout.p.handle) == '\n');
    }
    else static if (T.length == 1 &&
                    isSomeString!(typeof(args[0])) && is(typeof(args[0]) : const(char)[]) &&
                    !isAggregateType!(typeof(args[0])))
    {
        // error: not Transformation coding

        // Specialization for strings - a very frequent case
        //enforce(fprintf(.stdout.p.handle, "%.*s\n",
        //                cast(int) args[0].length, args[0].ptr) >= 0);

		stdout.write(args, '\n');
    }
    else
    {
        // Most general instance
        stdout.write(args, '\n');
    }
}
Comment 1 Berni44 2021-02-20 14:21:23 UTC
I get:

test.d(6): Error: undefined identifier stdio in package core.stdc, perhaps add static import core.stdc.stdio;

making the import static, like suggested yields:

test.d(6): Error: undefined identifier fwide

A working example (or a description what fails) would be nice...
Comment 2 Berni44 2021-04-12 18:01:41 UTC
I'm closing this, because it's unclear, what the bug is and the report is old, so it might not even be there anymore. Please feel free to reopen it, if you think, the bug still persists.
Comment 3 ag0aep6g 2021-04-13 10:49:31 UTC
(In reply to Berni44 from comment #2)
> I'm closing this, because it's unclear, what the bug is and the report is
> old, so it might not even be there anymore. Please feel free to reopen it,
> if you think, the bug still persists.

Reopening. The code is just missing some imports. Fixed test case:

----
import core.stdc.wchar_, core.stdc.locale;
static import core.stdc.stdio;
import std.stdio: writeln;

extern(C) int setlocale(int, char*);
static this()
{
    fwide(core.stdc.stdio.stdout, 1);
    setlocale(0, cast(char*)"china");
}
int main(string[] argv)
{
   writeln("1个");
   return 0;
}
----
Comment 4 Berni44 2021-04-13 11:07:22 UTC
Thanks. That makes more sense. I guess the expected output should be "1个" instead of "1?,?"?
Comment 5 dlangBugzillaToGithub 2024-12-01 16:15:38 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9938

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB