Evaluating __FILE__ and __LINE__ of caller?

Adam D. Ruppe destructionator at gmail.com
Fri Mar 2 18:09:51 PST 2012


On Saturday, 3 March 2012 at 01:46:05 UTC, Andrej Mitrovic wrote:
> Well, there is a way but it might wreak havoc on your object 
> size since it will instantiate a lot of templates.


Since some time last year, it works on all functions, just
use regular default parameters:

// test9.d
import std.stdio;

void a(string file = __FILE__, int line = __LINE__) {
         writeln("called from ", file, ":", line);
}

void main() {
         a;
         a;
         a;
}
//
dmd test9
test9
called from test9.d:8
called from test9.d:9
called from test9.d:10


More information about the Digitalmars-d-learn mailing list