dmd 1.062 and 2.047 release

Sean Kelly sean at invisibleduck.org
Mon Jun 14 15:45:06 PDT 2010


torhu Wrote:

> I tried the example on page 406-407 of the book (copying stdin to stdout 
> using message passing).  I don't mean to be a killjoy, but it doesn't 
> compile. :(
> 
> I'm using the latest pdf version of the book, and dmd 2.047.
> 
> 
> I get this:
> 
> ---
> d:\prog\dmd\bin\..\src\phobos\std\stdio.d(1902): Error: cannot 
> implicitly conver
> t expression (buffer) of type ubyte[] to immutable(ubyte)[]
> d:\prog\dmd\bin\..\src\phobos\std\stdio.d(7): Error: template instance 
> std.stdio
> .chunks.opApply!(int delegate(ref immutable(ubyte)[] __applyArg0)) error 
> instant
> iating
> ---

stdin.byChunk uses a mutable buffer that's overwritten for each chunk so you can't ask for an immutable ubyte[] in the foreach line.  Here's the version of that sample I used to test (13.7):

import std.algorithm, std.concurrency, std.stdio;

void main()
{
    enum bufferSize = 10;
    auto tid = spawn( &fileWriter );
    // Read loop
    foreach( ubyte[] buffer; stdin.byChunk( bufferSize ) )
        send( tid, buffer.idup );
}

void fileWriter()
{
    // Write loop
    for( ; ; )
    {
        auto buffer = receiveOnly!(immutable(ubyte)[])();
        writeln( "rx: ", buffer );
    }
}


More information about the Digitalmars-d-announce mailing list