www.digitalmars.com         C & C++   DMDScript  

D - logging without a preprocessor

reply Marcelo Fontenele S Santos <msantos pobox.com> writes:
I would like to write the file name, line number and function I'm at to 
a log file.

In C/C++ there is: __FILE__, __LINE__, __FUNCTION__ ( 
__PRETTY_FUNCTION__ in gcc)

How can this be done in D?

I read in a previous message of something like: build.line or debug.line.

Is this implemented? I tried in dli-0.1.2 but it didn't work.

PS:

A documentation fix is needed in http://digitalmars.com/d/pretod.html

<snip>

The C Preprocessor Way

	#define X(i)	((i) = (i) / 3)
	

The D Way

	int X(int i) { return i = i / 3; }
	

The compiler optimizer will inline it; no efficiency is lost.
</snip>

The C version sets the value of "i" while the d version doesn't, "i" is 
passed to the function by value. It should be "inout int i".

Thanks,
-- 
Marcelo Fontenele S Santos <msantos pobox.com>
Mar 12 2003
parent "Walter" <walter digitalmars.com> writes:
"Marcelo Fontenele S Santos" <msantos pobox.com> wrote in message
news:b4oula$2t4k$1 digitaldaemon.com...
 I would like to write the file name, line number and function I'm at to
 a log file.

 In C/C++ there is: __FILE__, __LINE__, __FUNCTION__ (
 __PRETTY_FUNCTION__ in gcc)

 How can this be done in D?
The only way to do this in D right now is to run the C preprocessor over the D source file, and run that result through the D compiler.
 A documentation fix is needed in http://digitalmars.com/d/pretod.html
Thanks, I'll fix it.
Mar 13 2003