writeln calls postblits constructor four times before print

bearophile bearophileHUGS at lycos.com
Wed Dec 11 10:32:26 PST 2013


FreeSlave:

> By the way, why does writeln able to print this struct? It has 
> no toString() method and its data is private. How does writeln 
> have access to it?

writeln is able to print structs that don't have a toString, this 
is very handy in most cases. When you don't want it, there's 
@disable, this doesn't link:

struct Foo {
     int x;
     //string toString() { return "x"; }
     @disable string toString();
}

void main() {
     import std.stdio;
     Foo f = Foo(10);
     writeln(f);
}


In theory this should be caught by writefln constraint before the 
linker. Probably I can turn this into a small enhancement request.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list