debug()
Orion-
thierry.passeron at gmail.com
Tue Feb 26 10:58:52 PST 2008
Hello people,
I'm just starting D programming. I'd like to make a printf like function to print some debuging informations. The synopsis could be dprintf(char[] format, ...) and as an example:
dprintf("creating object at %a", self);
It would print something like:
debug: class1.d(13): creating object at 0XFFB8
where class1.d is the __FILE__ name and 13 is the __LINE__ where it was called.
So, here are my 2 questions:
* How do you know 'self' inside a class member function in D?
* How would you do to have __LINE__ being the line where dprintf was called not the line where it is implemented ?
Here is my dprintf function so far:
void dprintf(...) {
TypeInfo[] infos;
void *data;
void putc(dchar c) { fputc(c, stderr); }
Box[] box1 = boxArray("debug: ");
Box[] box2 = boxArray(_arguments, cast(void *)_argptr);
boxArrayToArguments(box1 ~ box2, infos, data);
std.format.doFormat(&putc, infos, cast(char *)data);
}
Regards,
Thierry
More information about the Digitalmars-d
mailing list