anyone knows how to print __FUNCTION__ in D? and __LINE__
dnewsgroup at billbaxter.com
Fri Feb 23 10:21:44 PST 2007
> BCS Wrote:
>> davidl wrote:
>>> in c we can print __FUNCTION__ __LINE__ to indicate where we are. in D
>>> how to do, couldn't find.....
>> I use:
>> writef(...) // at run time
>> pragma(msg, ...)// at compile time
>> Not quite as useful but close.
> I disagree about the 'close' part: in C, you wrap __FILE__ or __LINE__ in a macro, so you have the value of the call site, in D if you put them in a default argument or in a template you have the current value, not the call site which is nearly useless..
> So let's not beat around the bush, this is an area where (AFAIK) C is superior to D..
You can use a mixin statement + new compile-time functions so that this
syntax is possible:
mixin( Pr("Error!") );
Pr is a charfunction(char) that returns a string like:
`writefln("%s(%s): %s", __FILE__, __LINE__, msg);`
But of course in C you could define your macro so that you can say just
Pr("Error!"), without needing the extra mixin( ... ) part. I think
there will eventually be a shortcut for mixin( ... ). Maybe #,$,@ or
something. Then you could have
More information about the Digitalmars-d-learn